h_mat
A type-safe and convenient heterogenous matrix type in Rust. Intended to use for an ECS with compile-time type-checking.
Basic usage
Creation and row access
Use extend to build the matrix, and use the get_row_ref/mut methods (with type annotations) to gain access to the individual rows.
// Creating a HMat with i32, f32, usize rows.
let mat: =
..;
// Access the rows explicitly as a reference.
let usize_row_ref: & = mat.get_row_ref;
let i32_row_ref: & = mat.get_row_ref;
// ... or as a mutable reference.
let mut mat = mat;
let i32_row_mut: &mut = mat.get_row_mut;
Column access
Note that the column types are written explicitly for reference. In general, they are inferred directly from the type of the matrix.
let mat = ..;
// Access a single column as a reference.
let col_ref: = mat.get_col_ref;
// ... or as a mutable reference...
let mut mat = mat;
let col_mut: = mat.get_col_mut;
// ... or directly move it out of the matrix.
let col: = mat.take_col;
// Then we can place it back to a different position.
mat.place_col;
Reforming
We can invoke HMatRef::reform to extract a reference matrix with arbitrary row order, i.e., a HMatRef, whose fields are indicated by the type annotation either at the let binding or the parameter.
let mat = ..;
// Reform as a heterogenous matrix of f32, and i32 rows.
let mat_ref: = reform;
// ... also works as an argument!
receive_reformed;
// Of course, we can access the rows/cols of the original matrix.
let i32_row_ref: & = mat_ref.get_row_ref;
let first_col_ref = mat_ref.get_col_ref;