SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. impl MyItem {
  10.     pub fn new() -> Self {
  11.         Self { fld1: String::new() }
  12.     }
  13. }
  14.  
  15.  
  16. pub struct MyObject<'item> {
  17.     pub item: &'item MyItem,
  18.     pub uuid: uuid::Uuid,
  19. }
  20.  
  21. impl<'item> MyObject<'item> {
  22.     fn new(item: &'item MyItem) -> Self {
  23.         MyObject {
  24.             item,
  25.             uuid: uuid::Uuid::new_v4(),
  26.         }
  27.     }
  28. }
  29.  
  30. impl<'item> Iterator for MyObject<'item> {
  31.     type Item = &'item MyItem;
  32.     fn next(&mut self) -> Option<Self::Item> {
  33.         Some(self.item)
  34.     }
  35. }
  36.  
  37. fn main() {
  38.     let item = MyItem::new();
  39.     let mut c = MyObject::new(&item);
  40.     println!("{}", c.next().unwrap().fld1);
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top