Guest User

Untitled

a guest
Sep 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. use std::iter::Sum;
  2.  
  3. pub struct M {
  4. i : i32
  5. }
  6.  
  7. #[derive(Debug)]
  8. pub struct N {
  9. k : i32
  10. }
  11.  
  12. impl Sum for M {
  13. fn sum<I : Iterator<Item = M>>(_iter : I) -> M {
  14. M { i : 32 }
  15. }
  16. }
  17.  
  18. impl<M> Sum<M> for N {
  19. fn sum<I : Iterator<Item = M >>(_iter : I) -> N {
  20. N { k : 1 }
  21. }
  22. }
  23.  
  24. fn main() {
  25. let a : Vec<M> = vec![M { i : 3 }];
  26. let x = a.iter().sum::<N>();
  27. println!("{:?}", x);
  28. }
Add Comment
Please, Sign In to add comment