pub trait MatrixFrom<T: ToMatrix> {
// Required method
fn matrix_from(input: Matrix<T>) -> Self;
}
Expand description
Trait for conversion between matrices of different types.
It only has a matrix_from()
method.
This is needed since negative trait bound are not supported in stable Rust
yet, so we’ll have a conflict trying to implement From
.
I plan to change this to the default From trait as soon as some sort
of specialization system is implemented.
You can track this issue here.
Required Methods§
Sourcefn matrix_from(input: Matrix<T>) -> Self
fn matrix_from(input: Matrix<T>) -> Self
Method for getting a matrix of a new type from a matrix of type Matrix<T>
.
§Example
use matrix_basic::Matrix;
use matrix_basic::MatrixFrom;
let a = Matrix::from(vec![vec![1, 2, 3], vec![0, 1, 2]]).unwrap();
let b = Matrix::from(vec![vec![1.0, 2.0, 3.0], vec![0.0, 1.0, 2.0]]).unwrap();
let c = Matrix::<f64>::matrix_from(a); // Type annotation is needed here
assert_eq!(c, b);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<T: ToMatrix, S: ToMatrix + From<T>> MatrixFrom<T> for Matrix<S>
Blanket implementation of MatrixFrom<T>
for converting Matrix<S>
to Matrix<T>
whenever
S
implements [From(T)
]. Look at matrix_into
.