Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. // use serde_derive; // 1.0.97
  2. use uuid; // 0.7.4
  3.  
  4. #[derive(Clone)]
  5. pub struct MyItem {
  6. pub fld1: String,
  7. }
  8.  
  9. pub struct MyObject {
  10. pub item: MyItem,
  11. pub uuid: uuid::Uuid,
  12. }
  13.  
  14. impl MyObject {
  15. fn new() -> Self {
  16. let m: MyItem = MyItem {
  17. fld1: String::new(),
  18. };
  19. MyObject {
  20. item: m,
  21. uuid: uuid::Uuid::new_v4(),
  22. }
  23. }
  24. }
  25.  
  26. impl Iterator for MyObject {
  27. type Item = MyItem;
  28. fn next(&mut self) -> Option<Self::Item> {
  29. Some(self.item.clone())
  30. }
  31. }
  32.  
  33. fn main() {
  34. let mut c = MyObject::new();
  35. println!("{}", c.next().unwrap().fld1);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement