Skip to content

Instantly share code, notes, and snippets.

Created January 18, 2018 10:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/6eb992ed912f80bf482431f9a149e992 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
use std::ops::Add;
pub struct SomeStruct<T> {
a: T,
b: T,
}
impl<T: Add<Output = T>> Iterator for SomeStruct<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
let res: T = self.b + self.b;
Some(res)
}
}
fn main() {
println!("{}", (SomeStruct { a: 4, b: 9 }).next().unwrap());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment