Skip to main content

project_cast

Macro project_cast 

Source
macro_rules! project_cast {
    ($x:ident : $type:ty => $type2:ty) => { ... };
}
Expand description

Projects a type as another type.

This performs a cast from one type to another, and is useful for creating generic shared objects based on traits rather than concrete types, and without having to make methods generic.

let projection = project_cast!(x: [i32; 3] => dyn std::ops::IndexMut<usize, Output = i32>);

let mut x = [1, 2, 3];
projection.project_mut(&mut x)[0] += 10;
assert_eq!(projection.project(&x)[0], 11);