SHARE
TWEET

Untitled

a guest Mar 18th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const SOME_CONDITION: bool = true;
  2.  
  3. fn main() {
  4.     let mut foo = Foo::default();
  5.     let foo = Foo::default().chain_move().chain_move();
  6.     let foo = if SOME_CONDITION {
  7.         foo.chain_move().chain_move().chain_move()
  8.     } else {
  9.         foo
  10.     };
  11.     consume_ref(&foo);
  12.     consume_move(foo);
  13. }
  14.  
  15. // ============================================================================
  16. // Shared definitions.
  17. // ============================================================================
  18.  
  19. #[derive(Debug, Default)]
  20. struct Foo {
  21.     value: usize,
  22. }
  23.  
  24. impl Foo {
  25.     fn chain_move(mut self) -> Self {
  26.         self.value += 1;
  27.         self
  28.     }
  29.  
  30.     fn chain_ref(&mut self) -> &mut Self {
  31.         self.value += 1;
  32.         self
  33.     }
  34. }
  35.  
  36. fn consume_move(foo: Foo) {
  37.     println!("{:?}", foo);
  38. }
  39.  
  40. fn consume_ref(foo: &Foo) {
  41.     println!("{:?}", foo);
  42. }
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