[][src]Trait idalloc::Id

pub trait Id: Copy + Display + Debug {
    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; }

A type that can be used an allocator index.

Required methods

fn initial() -> Self

Allocate the initial, unallocated value.

Examples

use idalloc::Id as _;

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

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());

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());

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);

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"));

fn none() -> Self

Construct the none sentinel value for this type.

Examples

use idalloc::Id as _;

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

fn is_none(self) -> bool

Test if the value is the none sentinel value.

Examples

use idalloc::Id as _;

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

Implementations on Foreign Types

impl Id for u8[src]

impl Id for u16[src]

impl Id for u32[src]

impl Id for u64[src]

impl Id for u128[src]

Loading content...

Implementors

Loading content...