Trait Id

Source
pub trait Id:
    Copy
    + Display
    + Debug {
    // Required methods
    fn initial() -> Self;
    fn as_usize(self) -> usize;
    fn increment(self) -> Self;
    fn take(&mut self) -> Self;
    fn expect(self, m: &str) -> Self;
    fn none() -> Self;
    fn is_none(self) -> bool;
}
Expand description

A type that can be used an allocator index.

Required Methods§

Source

fn initial() -> Self

Allocate the initial, unallocated value.

§Examples
use idalloc::Id as _;

assert_eq!(0, u16::initial());
assert_eq!(0, u16::initial());
Source

fn as_usize(self) -> usize

Get the index as a usize.

§Examples
use idalloc::Id as _;

assert_eq!(42, 42u16.as_usize());
assert_eq!(42, 42u32.as_usize());
Source

fn increment(self) -> Self

Increment the index and return the incremented value.

§Examples
use idalloc::Id as _;

assert_eq!(1, 0u16.increment());
assert_eq!(1, 0u32.increment());
Source

fn take(&mut self) -> Self

Take the value and replace the existing value with the none variant.

§Examples
use idalloc::Id as _;

let mut v = 1u32;
assert_eq!(1u32, v.take());
assert_eq!(u32::none(), v);
Source

fn expect(self, m: &str) -> Self

Test if the current value is none, and panic with the given message if if is.

§Examples
use idalloc::Id as _;

let mut v = 1u32;
assert_eq!(1u32, v.expect("value must be defined"));
Source

fn none() -> Self

Construct the none sentinel value for this type.

§Examples
use idalloc::Id as _;

assert!(u32::none().is_none());
Source

fn is_none(self) -> bool

Test if the value is the none sentinel value.

§Examples
use idalloc::Id as _;

assert!(u32::none().is_none());

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.

Implementations on Foreign Types§

Source§

impl Id for u8

Source§

fn initial() -> Self

Source§

fn as_usize(self) -> usize

Source§

fn increment(self) -> Self

Source§

fn take(&mut self) -> Self

Source§

fn expect(self, m: &str) -> Self

Source§

fn none() -> Self

Source§

fn is_none(self) -> bool

Source§

impl Id for u16

Source§

fn initial() -> Self

Source§

fn as_usize(self) -> usize

Source§

fn increment(self) -> Self

Source§

fn take(&mut self) -> Self

Source§

fn expect(self, m: &str) -> Self

Source§

fn none() -> Self

Source§

fn is_none(self) -> bool

Source§

impl Id for u32

Source§

fn initial() -> Self

Source§

fn as_usize(self) -> usize

Source§

fn increment(self) -> Self

Source§

fn take(&mut self) -> Self

Source§

fn expect(self, m: &str) -> Self

Source§

fn none() -> Self

Source§

fn is_none(self) -> bool

Source§

impl Id for u64

Source§

fn initial() -> Self

Source§

fn as_usize(self) -> usize

Source§

fn increment(self) -> Self

Source§

fn take(&mut self) -> Self

Source§

fn expect(self, m: &str) -> Self

Source§

fn none() -> Self

Source§

fn is_none(self) -> bool

Source§

impl Id for u128

Source§

fn initial() -> Self

Source§

fn as_usize(self) -> usize

Source§

fn increment(self) -> Self

Source§

fn take(&mut self) -> Self

Source§

fn expect(self, m: &str) -> Self

Source§

fn none() -> Self

Source§

fn is_none(self) -> bool

Implementors§