Struct andex::Andex [−][src]
pub struct Andex<const SIZE: usize>(_);
Expand description
Array index generic type
This is the type of the array index that receives the size of
the array as a const generic SIZE parameter.
Note: the maximum numerical value in the andex is SIZE - 1.
Example
This should be used in a type alias, as such:
use andex::*; type MyIdx = Andex<12>;
Implementations
The SIZE parameter, which is the size of the array that this
andex indexes.
Create a new andex instance
Bounds are checked at compile time when this is used to create
const instances - that’s why this is the recommended usage:
use andex::*; type MyIdx = Andex<12>; const MYVALUE : MyIdx = MyIdx::new::<0>();
And that’s why the following doesn’t compile:
use andex::*; type MyIdx = Andex<12>; const MYVALUE : MyIdx = MyIdx::new::<12>();
Extracts the numeric value of the index, consuming it
Iterate all possible values of the index
Useful to loop over an array inside a struct, without
holding a reference to the whole struct in the loop.
Example
use andex::*; #[derive(Default)] pub struct Scores([u32; PlayerId::SIZE]); type PlayerId = Andex<12>; impl_andex_for!(Scores, u32, PlayerId); #[derive(Default)] struct Game { scores: Scores, } fn function(game: &Game) { for i in PlayerId::iter() { println!("score of player {} is {}", i, game.scores[i]); } }
Indexes the provided array
Used internally by the Index trait implementation.
Mut-indexes the provided array
Used internally by the IndexMut trait implementation.
Trait Implementations
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
Auto Trait Implementations
impl<const SIZE: usize> RefUnwindSafe for Andex<SIZE>
impl<const SIZE: usize> UnwindSafe for Andex<SIZE>
Blanket Implementations
Mutably borrows from an owned value. Read more