Guest User

Untitled

a guest
Jul 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #![allow(unused_variable)]
  2. struct test(i32);
  3.  
  4. fn main()
  5. {
  6. let matrix = Matrix::new([2, 2], vec![1, 2, 3, 4]).unwrap();
  7. println!("{:?}", matrix);
  8. }
  9.  
  10. struct Matrix<T>
  11. {
  12. nums: Vec<T>,
  13. row: u32,
  14. col: u32,
  15. }
  16.  
  17. impl<T> std::fmt::Debug for Matrix<T>
  18. where T: std::fmt::Debug
  19. {
  20. fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result
  21. {
  22. write!(f, "duh")
  23. }
  24. }
  25.  
  26. impl<T> Matrix<T>
  27. where T: std::ops::Mul + std::ops::Sub + std::ops::Add + std::ops::Div
  28. {
  29. fn new(d: [u32; 2], nums: Vec<T>) -> Option<Matrix<T>>
  30. {
  31. if d[0] * d[1] != nums.len() as u32 { return None; }
  32. Some(Matrix
  33. {
  34. nums: nums,
  35. row: d[0],
  36. col: d[1],
  37. })
  38. }
  39. }
Add Comment
Please, Sign In to add comment