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

source

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)

source

pub fn start(&self) -> Option<i64>

Returns the start of the range

source

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.

source

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.

source

pub fn contains(&self, n: KNumber) -> bool

Returns true if the provided number is within the range

source

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.

source

pub fn intersection(&self, other: &KRange) -> Option<Self>

Returns the intersection of two ranges

source

pub fn is_ascending(&self) -> bool

Returns true if the range’s start is less than or equal to its end

source

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.

source

pub fn is_bounded(&self) -> bool

Returns true if the range has defined start and end boundaries

source

pub fn pop_front(&mut self) -> Result<Option<i64>, Error>

Removes and returns the first element in the range.

This is used by RangeIterator and in the VM to iterate over temporary ranges.

Returns an error if the range is not bounded.

source

pub fn pop_back(&mut self) -> Result<Option<i64>, Error>

Removes and returns the first element in the range.

This is used by RangeIterator and in the VM to iterate over temporary ranges.

Returns an error if the range is not bounded.

Trait Implementations§

source§

impl Clone for KRange

source§

fn clone(&self) -> KRange

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for KRange

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for KRange

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<KRange> for KValue

source§

fn from(value: KRange) -> Self

Converts to this type from the input type.
source§

impl<R> From<R> for KRange
where R: RangeBounds<i64>,

source§

fn from(range: R) -> Self

Converts to this type from the input type.
source§

impl Hash for KRange

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for KRange

source§

fn eq(&self, other: &KRange) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for KRange

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.