Macro andex::impl_deref_for[][src]

macro_rules! impl_deref_for {
    ($name : ty, $base : ty, $andex : ty) => { ... };
}
Expand description

Implement Deref for the wrapped array, making the wrapper behave like it except for only being indexable with the andex.

Example

use andex::*;
use andex::impl_andex_for;
use andex::impl_deref_for;

#[derive(Default)]
pub struct MyU32([u32; MyIdx::SIZE]);
type MyIdx = Andex<12>;
impl_andex_for!(MyU32, u32, MyIdx);

// Use `impl_deref_for` to make MyU32 behave like an array
impl_deref_for!(MyU32, u32, MyIdx);

fn example() {
    let myu32 = MyU32::default();
    // We can now use `iter` directly in the wrapper:
    for value in myu32.iter() {
        println!("value {}", value);
    }
    // But still only index with an andex:
    println!("{}", myu32[MyIdx::new::<0>()]);
}