Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #[derive(Copy, Clone, Debug)]
  2. struct Matrix {
  3. inner: [[u8; 2]; 2]
  4. }
  5.  
  6. impl std::ops::Mul<Matrix> for u8 {
  7. type Output = Matrix;
  8. fn mul(self, Matrix { inner: right }: Matrix) -> Matrix {
  9. let mut inner = [[0; 2]; 2];
  10. for i in 0..2 {
  11. for j in 0..2 {
  12. inner[i][j] = self * right[i][j];
  13. }
  14. }
  15. Matrix { inner }
  16. }
  17. }
  18.  
  19. fn main(){
  20. let result = 5 * Matrix { inner: [[1, 2], [3, 4]] };
  21. println!("{:?}", result);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement