stable_id_traits/
lib.rs

1mod cast_usize;
2mod maximum;
3mod predecessor;
4mod successor;
5
6/**
7Predecessor trait for numbers.
8*/
9pub trait Predecessor {
10    /// Return `self` - 1. Panics when `self` is at 0.
11    fn prev_value(self) -> Self;
12}
13
14/**
15Successor trait for numbers.
16*/
17pub trait Successor {
18    /// Return `self` + 1. Panics if `self` is at maximum value.
19    fn next_value(self) -> Self;
20}
21
22/**
23A trait that describes the max value of an unsigned integer. This trait is used to detect overflow.
24Also, it's used like a NULL terminator for the free list in [`Tec`].
25*/
26pub trait Maximum {
27    /// Generally this should be `X::MAX`, where `X` is an unsigned integer. The value is used to detect overflow.
28    fn max_value() -> Self;
29}
30
31/**
32Trait for casting between an unsigned integer to a usize, and vice versa.
33Note: to() would panic if the value is greater or equal to the type's max.
34*/
35pub trait CastUsize {
36    /** Turning an unsigned integer into a usize. */
37    fn cast_to(self) -> usize;
38    /** Turning a usize into an unsigned integer. */
39    fn cast_from(val: usize) -> Self;
40}
41
42/**
43Trait for projecting the inner value of the Id's tuple, i.e. returning u32 for Id(u32).
44 */
45pub trait Inner<T> {
46    /** Return the inner value of the Id, i.e. returning u32 for Id(u32) */
47    fn project(self) -> T;
48}