Offset

Trait Offset 

Source
pub trait Offset:
    Clone
    + Debug
    + Neg
    + PartialEq
    + Eq {
    // Required methods
    fn try_increment(&mut self) -> Option<()>;
    fn try_decrement(&mut self) -> Option<()>;
    fn zero() -> Self;
    fn index_input(&self, input: Self) -> Option<usize>;
    fn index_output(&self, inner: usize) -> Option<Self>;
}
Expand description

Types that can be used as an index for a Deque.

The (fallible) operations required are a very limited subset of arithmetic, combined with conversion between Offset and usize.

The provided generic implementation covers isize, i64, etc.

Required Methods§

Source

fn try_increment(&mut self) -> Option<()>

Should return None on overflow. Currently, this will cause the library to panic, but that may not always be the case.

Source

fn try_decrement(&mut self) -> Option<()>

Should return None on overflow. Currently, this will cause the library to panic, but that may not always be the case.

Source

fn zero() -> Self

Source

fn index_input(&self, input: Self) -> Option<usize>

Should return Some(input - self), or None on overflow.

Overflows can easily happen with a very old index, if the index type is bigger than usize; this is handled gracefully by the library. So index_input must not panic on overflow.

Source

fn index_output(&self, inner: usize) -> Option<Self>

Should return Some(output + self).

Should return None on overflow; Currently, this will cause the library to panic, but that may not always be the case.

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.

Implementors§