pub trait DiscreteRangedwhere
Self: Ranged,{
// Required methods
fn size(&self) -> usize;
fn index_of(&self, value: &Self::ValueType) -> Option<usize>;
fn from_index(&self, index: usize) -> Option<Self::ValueType>;
// Provided methods
fn values(&self) -> DiscreteValueIter<'_, Self>
where Self: Sized { ... }
fn previous(&self, value: &Self::ValueType) -> Option<Self::ValueType> { ... }
fn next(&self, value: &Self::ValueType) -> Option<Self::ValueType> { ... }
}
Expand description
The trait indicates the coordinate is discrete This means we can bidirectionally map the range value to 0 to N in which N is the number of distinct values of the range.
This is useful since for a histgoram, this is an abstraction of bucket.
Required Methods§
Sourcefn size(&self) -> usize
fn size(&self) -> usize
Get the number of element in the range Note: we assume that all the ranged discrete coordinate has finite value
- returns The number of values in the range
Sourcefn index_of(&self, value: &Self::ValueType) -> Option<usize>
fn index_of(&self, value: &Self::ValueType) -> Option<usize>
Map a value to the index
Note: This function doesn’t guarantee return None when the value is out of range. The only way to confirm the value is in the range is to examining the return value isn’t larger than self.size.
value
: The value to map- returns The index of the value
Sourcefn from_index(&self, index: usize) -> Option<Self::ValueType>
fn from_index(&self, index: usize) -> Option<Self::ValueType>
Reverse map the index to the value
Note: This function doesn’t guarantee returning None when the index is out of range.
value
: The index to map- returns The value
Provided Methods§
Sourcefn values(&self) -> DiscreteValueIter<'_, Self>where
Self: Sized,
fn values(&self) -> DiscreteValueIter<'_, Self>where
Self: Sized,
Return a iterator that iterates over the all possible values
- returns The value iterator
Sourcefn previous(&self, value: &Self::ValueType) -> Option<Self::ValueType>
fn previous(&self, value: &Self::ValueType) -> Option<Self::ValueType>
Returns the previous value in this range
Normally, it’s based on the from_index
and index_of
function. But for
some of the coord spec, it’s possible that we value faster implementation.
If this is the case, we can impelemnet the type specific impl for the previous
and next
.
value
: The current value- returns: The value piror to current value
Sourcefn next(&self, value: &Self::ValueType) -> Option<Self::ValueType>
fn next(&self, value: &Self::ValueType) -> Option<Self::ValueType>
Returns the next value in this range
Normally, it’s based on the from_index
and index_of
function. But for
some of the coord spec, it’s possible that we value faster implementation.
If this is the case, we can impelemnet the type specific impl for the previous
and next
.
value
: The current value- returns: The value next to current value
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.