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> {
// Required methods
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;
}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§
Sourcefn unwrap(self) -> T
fn unwrap(self) -> T
Convert the index into its underlying integer type. Panic if index is invalid.
Sourcefn expect(self, msg: &str) -> T
fn expect(self, msg: &str) -> T
Convert the index into its underlying integer type. In case of failure, report the given message.
Sourcefn map<F: FnOnce(T) -> T>(self, f: F) -> Self
fn map<F: FnOnce(T) -> T>(self, f: F) -> Self
Map the underlying integer type. This allows restricting operations to valid indices only.
Sourcefn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U
fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U
Map the underlying integer type. If the index is invalid, output the provided default.
Sourcefn into_inner(self) -> T
fn into_inner(self) -> T
Produce the raw inner type without checking.
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.