Trait gut::index::CheckedIndex[][src]

pub trait CheckedIndex<T>: From<T> + Into<Option<T>> + Add<Self, Output = Self, Output = Self> + Add<T> + Sub<Self, Output = Self, Output = Self> + Sub<T> + Mul<T, Output = Self> + Div<T, Output = Self> + Rem<T, Output = Self> {
    fn invalid() -> Self;
fn is_valid(&self) -> bool;
fn unwrap(self) -> T;
fn expect(self, msg: &str) -> T;
fn map<F>(self, f: F) -> Self
    where
        F: FnOnce(T) -> T
;
fn map_or<U, F>(self, default: U, f: F) -> U
    where
        F: FnOnce(T) -> U
;
fn into_inner(self) -> T; }
Expand description

A trait that defines what it means for an index to be a checked index. In other words implementers are indices that are checked for validity in some way.

Required methods

Construct an invalid index.

Check if the index is valid.

Convert the index into its underlying integer type. Panic if index is invalid.

Convert the index into its underlying integer type. In case of failure, report the given message.

Map the underlying integer type. This allows restricting operations to valid indices only.

Map the underlying integer type. If the index is invalid, output the provided default.

Produce the raw inner type without checking.

Implementors