Uses old Rust 2015
0.3.3 |
|
---|---|
0.3.2 |
|
0.2.1 |
|
0.1.1 |
|
#380 in #stack
99KB
2.5K
SLoC
rowcol
rowcol
crate provides fixed-size Vector
and Matrix
.
Their length or number of rows/columns are specified as type parameters,
using type-level numbers provided by typenum
crate.
lib.rs
:
rowcol crate provides fixed-size Vector
and Matrix
.
Their length or number of rows/columns are specified as type parameters,
using type-level numbers provided by typenum crate.
This lets vectors and matrices be internally represented as fixed-length arrays,
therefore they are allocated on the stack, and becomes Copy
if their content
is Copy
. Also, errors like computing the determinant of a non-square matrix
can be detected at compile-time, instead of causing runtime panic.
#[macro_use] extern crate rowcol;
use rowcol::prelude::*;
fn fib(n: usize) -> u64 {
// inferred as `f: Vector<u64, U2>`
let f = vector![1, 0];
// inferred as `a: Matrix<u64, U2, U2>`
let a = matrix![[1, 1], [1, 0]];
(a.pow(n) * f)[1]
}
assert_eq!(fib(0), 0);
assert_eq!(fib(10), 55);
assert_eq!(fib(50), 12586269025);
Dependencies
~340–530KB