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§
Sourcefn initial() -> Self
fn initial() -> Self
Allocate the initial, unallocated value.
§Examples
use idalloc::Id as _;
assert_eq!(0, u16::initial());
assert_eq!(0, u16::initial());
Sourcefn as_usize(self) -> usize
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());
Sourcefn increment(self) -> Self
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());
Sourcefn take(&mut self) -> Self
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);
Sourcefn expect(self, m: &str) -> Self
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"));
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.