Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unused_variable)]
- struct test(i32);
- fn main()
- {
- let matrix = Matrix::new([2, 2], vec![1, 2, 3, 4]).unwrap();
- println!("{:?}", matrix);
- }
- struct Matrix<T>
- {
- nums: Vec<T>,
- row: u32,
- col: u32,
- }
- impl<T> std::fmt::Debug for Matrix<T>
- where T: std::fmt::Debug
- {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result
- {
- write!(f, "duh")
- }
- }
- impl<T> Matrix<T>
- where T: std::ops::Mul + std::ops::Sub + std::ops::Add + std::ops::Div
- {
- fn new(d: [u32; 2], nums: Vec<T>) -> Option<Matrix<T>>
- {
- if d[0] * d[1] != nums.len() as u32 { return None; }
- Some(Matrix
- {
- nums: nums,
- row: d[0],
- col: d[1],
- })
- }
- }
Add Comment
Please, Sign In to add comment