macro_rules! impl_vector {
    ($Vector: ident { $($field: ident), + }, $len: expr) => { ... };
}
Expand description

Macros for implementing Vector functions & constants in structs.

Example

struct Vector5<T> {
    x: T,
    y: T,
    z: T,
    w: T,
    v: T,
}
 
impl_vector!(Vector5 { x, y, z, w, v }, 5);
 
// Now the struct has generic Vector methods.
let vector = Vector5::new(1, 2, 3, 4, 5);
assert_eq!(format!("{}", vector), "(1, 2, 3, 4, 5)");
 
assert_eq!(Vector5::NAME, "Vector5");
assert_eq!(Vector5::LEN, 5);

Parameters

$Vector: ident // Name of the Vector Struct
{ $($field: ident), + } // Fields within the Vector Struct
$len: expr // The amount of fields within the Vector Struct

Impl Constants

pub const NAME: &'static str = stringify!($Vector)
pub const SIZE: usize = core::mem::size_of::<T>() * $len
pub const LEN: usize = $len

Impl Functions

pub const fn new( $($field: T), + ) -> $Vector<T>
pub fn to_array(self) -> [T; $len]
pub fn to_vec(self) -> Vec<T>

Impl Traits

impl<T> Vector<T, $len> for $Vector<T>
impl<T: PrimInt> IntegerVector<T, $len> for $Vector<T>
impl<T: Float> FloatingPointVector<T, $len> for $Vector<T>

To see more implemented traits & functions, see the source code.