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

pub trait CheckedIndex<T>: From<T> + Into<Option<T>> + Add<Output = Self> + Add<T, Output = Self> + Sub<Output = Self> + Sub<T, Output = Self> + 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: FnOnce(T) -> T>(self, f: F) -> Self;
fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U;
fn into_inner(self) -> T; }

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

fn invalid() -> Self[src]

Construct an invalid index.

fn is_valid(&self) -> bool[src]

Check if the index is valid.

fn unwrap(self) -> T[src]

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

fn expect(self, msg: &str) -> T[src]

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

fn map<F: FnOnce(T) -> T>(self, f: F) -> Self[src]

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

fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U[src]

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

fn into_inner(self) -> T[src]

Produce the raw inner type without checking.

Loading content...

Implementors

impl CheckedIndex<usize> for Index[src]

Loading content...