SHARE
TWEET

Untitled

a guest Aug 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Foo<T, C> where C: Fn() -> T {
  2.     make_t: C,
  3.     value: Option<T>,
  4. }
  5.  
  6. impl<T, C> Foo<T, C> where C: Fn() -> T {
  7.     fn new(make_t: C) -> Foo<T, C> {
  8.         Foo {
  9.             make_t,
  10.             value: None
  11.         }
  12.     }
  13.    
  14.     fn value(&mut self) -> &T {
  15.         self.value
  16.             .get_or_insert_with(&self.make_t)
  17.     }
  18. }
  19.  
  20. fn main() {
  21.     let mut bar = Foo::new(|| 3);
  22.    
  23.     println!("{}", bar.value());
  24. }
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