Struct koto_runtime::KRange
source · pub struct KRange(/* private fields */);
Expand description
The integer range type used by the Koto runtime
See KValue::Range
Implementations§
source§impl KRange
impl KRange
sourcepub fn new(start: Option<i64>, end: Option<(i64, bool)>) -> Self
pub fn new(start: Option<i64>, end: Option<(i64, bool)>) -> Self
Initializes a range with the given start and end bounds
The end bound has an additional flag that specifies whether or not the end of the range is inclusive or not.
KRange
has an implementation of From
for implementations of RangeBounds
which might be
simpler to use, e.g. KRange::from(10..=20)
sourcepub fn end(&self) -> Option<(i64, bool)>
pub fn end(&self) -> Option<(i64, bool)>
Returns the end of the range
The return value includes flag stating whether or not the range end is inclusive or not.
sourcepub fn as_sorted_range(&self) -> Range<i64>
pub fn as_sorted_range(&self) -> Range<i64>
Returns a sorted translation of the range with missing boundaries replaced by min/max values
No clamping of the range boundaries is performed (as in KRange::indices), so negative indices will be preserved.
sourcepub fn contains(&self, n: KNumber) -> bool
pub fn contains(&self, n: KNumber) -> bool
Returns true if the provided number is within the range
sourcepub fn indices(&self, max_index: usize) -> Range<usize>
pub fn indices(&self, max_index: usize) -> Range<usize>
Returns the range translated into non-negative indices, suitable for container access
The start index will be clamped to the range 0..=max_index
.
The end index will be clamped to the range start..=max_index
If the start value is None
then the resulting start index will be 0
.
If the end value is None
then the resulting end index will be max_index
.
sourcepub fn intersection(&self, other: &KRange) -> Option<Self>
pub fn intersection(&self, other: &KRange) -> Option<Self>
Returns the intersection of two ranges
sourcepub fn is_ascending(&self) -> bool
pub fn is_ascending(&self) -> bool
Returns true if the range’s start is less than or equal to its end
sourcepub fn size(&self) -> Option<usize>
pub fn size(&self) -> Option<usize>
Returns the size of the range if both start and end boundaries are specified
Descending ranges have a non-negative size, i.e. the size is equal to start - end
.
sourcepub fn is_bounded(&self) -> bool
pub fn is_bounded(&self) -> bool
Returns true if the range has defined start and end boundaries
Trait Implementations§
source§impl PartialEq for KRange
impl PartialEq for KRange
impl Eq for KRange
impl StructuralPartialEq for KRange
Auto Trait Implementations§
impl Freeze for KRange
impl RefUnwindSafe for KRange
impl Send for KRange
impl Sync for KRange
impl Unpin for KRange
impl UnwindSafe for KRange
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
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.