pub struct GenericRange<T> {
start: Option<T>,
end: Option<T>,
}
Expand description
A half-open time range.
The range contains values that value >= start
and val < end
.
The range is empty iff start == end == "the default value of T"
Fields§
§start: Option<T>
§end: Option<T>
Implementations§
source§impl<T> GenericRange<T>
impl<T> GenericRange<T>
sourcepub fn and(&self, other: &GenericRange<T>) -> GenericRange<T>
pub fn and(&self, other: &GenericRange<T>) -> GenericRange<T>
Computes the AND’ed range with other.
sourcepub fn or(&self, other: &GenericRange<T>) -> GenericRange<T>
pub fn or(&self, other: &GenericRange<T>) -> GenericRange<T>
Compute the OR’ed range of two ranges.
Notice: this method does not compute the exact OR’ed operation for simplicity.
For example, [1, 2)
or’ed with [4, 5)
will produce [1, 5)
instead of [1, 2) ∪ [4, 5)
sourcepub fn intersects(&self, target: &GenericRange<T>) -> bool
pub fn intersects(&self, target: &GenericRange<T>) -> bool
Checks if current range intersect with target.
sourcepub fn empty() -> GenericRange<T>
pub fn empty() -> GenericRange<T>
Create an empty range.
sourcefn from_optional(start: Option<T>, end: Option<T>) -> GenericRange<T>
fn from_optional(start: Option<T>, end: Option<T>) -> GenericRange<T>
Create GenericRange from optional start and end.
If the present value of start >= the present value of end, it will return an empty range
with the default value of T
.
source§impl<T> GenericRange<T>
impl<T> GenericRange<T>
sourcepub fn new<U: PartialOrd + Into<T>>(start: U, end: U) -> Option<GenericRange<T>>
pub fn new<U: PartialOrd + Into<T>>(start: U, end: U) -> Option<GenericRange<T>>
Creates a new range that contains values in [start, end)
.
Returns None
if start
> end
.
sourcepub fn min_to_max() -> GenericRange<T>
pub fn min_to_max() -> GenericRange<T>
Return a range containing all possible values.
sourcepub fn contains<U: PartialOrd<T>>(&self, target: &U) -> bool
pub fn contains<U: PartialOrd<T>>(&self, target: &U) -> bool
Returns true if timestamp
is contained in the range.
source§impl<T: PartialOrd> GenericRange<T>
impl<T: PartialOrd> GenericRange<T>
source§impl GenericRange<Timestamp>
impl GenericRange<Timestamp>
sourcepub fn new_inclusive(start: Option<Timestamp>, end: Option<Timestamp>) -> Self
pub fn new_inclusive(start: Option<Timestamp>, end: Option<Timestamp>) -> Self
Create a TimestampRange with optional inclusive end timestamp. If end timestamp is present and is less than start timestamp, this method will return an empty range.
§Caveat
If the given end timestamp’s value is i64::MAX
, which will result into overflow when added
by 1(the end is inclusive), this method does not try to convert the time unit of end
timestamp, instead it just return [start, INF)
. This exaggerates the range but does not
affect correctness.
sourcepub fn with_unit(start: i64, end: i64, unit: TimeUnit) -> Option<Self>
pub fn with_unit(start: i64, end: i64, unit: TimeUnit) -> Option<Self>
Shortcut method to create a timestamp range with given start/end value and time unit.
Returns empty iff start
> end
.
sourcepub fn single(ts: Timestamp) -> Self
pub fn single(ts: Timestamp) -> Self
Create a range that containing only given ts
.
§Notice:
Left-close right-open range cannot properly represent range with a single value.
For simplicity, this implementation returns an approximate range [ts, ts+1)
instead.
sourcepub fn from_start(start: Timestamp) -> Self
pub fn from_start(start: Timestamp) -> Self
Create a range [start, INF)
.
§Notice
Left-close right-open range cannot properly represent range with exclusive start like: (start, ...)
.
You may resort to [start-1, ...)
instead.
Trait Implementations§
source§impl<T: Clone> Clone for GenericRange<T>
impl<T: Clone> Clone for GenericRange<T>
source§fn clone(&self) -> GenericRange<T>
fn clone(&self) -> GenericRange<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for GenericRange<T>
impl<T: Debug> Debug for GenericRange<T>
source§impl<'de, T> Deserialize<'de> for GenericRange<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for GenericRange<T>where
T: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<T: Hash> Hash for GenericRange<T>
impl<T: Hash> Hash for GenericRange<T>
source§impl<T: PartialEq> PartialEq for GenericRange<T>
impl<T: PartialEq> PartialEq for GenericRange<T>
source§impl<T> Serialize for GenericRange<T>where
T: Serialize,
impl<T> Serialize for GenericRange<T>where
T: Serialize,
impl<T: Copy> Copy for GenericRange<T>
impl<T: Eq> Eq for GenericRange<T>
impl<T> StructuralPartialEq for GenericRange<T>
Auto Trait Implementations§
impl<T> Freeze for GenericRange<T>where
T: Freeze,
impl<T> RefUnwindSafe for GenericRange<T>where
T: RefUnwindSafe,
impl<T> Send for GenericRange<T>where
T: Send,
impl<T> Sync for GenericRange<T>where
T: Sync,
impl<T> Unpin for GenericRange<T>where
T: Unpin,
impl<T> UnwindSafe for GenericRange<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CallHasher for T
impl<T> CallHasher for T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request