pub trait MulFrom<Lhs = Self> {
fn mul_from(&mut self, lhs: Lhs);
}
Expand description
Compound multiplication and assignment to the rhs operand.
rhs.mul_from(lhs)
has the same effect as rhs = lhs * rhs
.
Examples
use rug::ops::MulFrom;
struct ColumnVec(i32, i32);
struct SquareMatrix(ColumnVec, ColumnVec);
impl MulFrom<&SquareMatrix> for ColumnVec {
fn mul_from(&mut self, lhs: &SquareMatrix) {
let SquareMatrix(ref left, ref right) = *lhs;
let out_0 = left.0 * self.0 + right.0 * self.1;
self.1 = left.1 * self.0 + right.1 * self.1;
self.0 = out_0;
}
}
let mut col = ColumnVec(2, 30);
let matrix_left = ColumnVec(1, -2);
let matrix_right = ColumnVec(3, -1);
let matrix = SquareMatrix(matrix_left, matrix_right);
// ( 1 3) ( 2) = ( 92)
// (-2 -1) (30) (-34)
col.mul_from(&matrix);
assert_eq!(col.0, 92);
assert_eq!(col.1, -34);