Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Copy, Clone, Debug)]
- struct Matrix {
- inner: [[u8; 2]; 2]
- }
- impl std::ops::Mul<Matrix> for u8 {
- type Output = Matrix;
- fn mul(self, Matrix { inner: right }: Matrix) -> Matrix {
- let mut inner = [[0; 2]; 2];
- for i in 0..2 {
- for j in 0..2 {
- inner[i][j] = self * right[i][j];
- }
- }
- Matrix { inner }
- }
- }
- fn main(){
- let result = 5 * Matrix { inner: [[1, 2], [3, 4]] };
- println!("{:?}", result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement