Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // use serde_derive; // 1.0.97
- use uuid; // 0.7.4
- #[derive(Clone)]
- pub struct MyItem {
- pub fld1: String,
- }
- impl MyItem {
- pub fn new() -> Self {
- Self { fld1: String::new() }
- }
- }
- pub struct MyObject<'item> {
- pub item: &'item MyItem,
- pub uuid: uuid::Uuid,
- }
- impl<'item> MyObject<'item> {
- fn new(item: &'item MyItem) -> Self {
- MyObject {
- item,
- uuid: uuid::Uuid::new_v4(),
- }
- }
- }
- impl<'item> Iterator for MyObject<'item> {
- type Item = &'item MyItem;
- fn next(&mut self) -> Option<Self::Item> {
- Some(self.item)
- }
- }
- fn main() {
- let item = MyItem::new();
- let mut c = MyObject::new(&item);
- println!("{}", c.next().unwrap().fld1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement