Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::iter::Sum;
- pub struct M {
- i : i32
- }
- #[derive(Debug)]
- pub struct N {
- k : i32
- }
- impl Sum for M {
- fn sum<I : Iterator<Item = M>>(_iter : I) -> M {
- M { i : 32 }
- }
- }
- impl<M> Sum<M> for N {
- fn sum<I : Iterator<Item = M >>(_iter : I) -> N {
- N { k : 1 }
- }
- }
- fn main() {
- let a : Vec<M> = vec![M { i : 3 }];
- let x = a.iter().sum::<N>();
- println!("{:?}", x);
- }
Add Comment
Please, Sign In to add comment