Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const SOME_CONDITION: bool = true;
- fn main() {
- let mut foo = Foo::default();
- let foo = Foo::default().chain_move().chain_move();
- let foo = if SOME_CONDITION {
- foo.chain_move().chain_move().chain_move()
- } else {
- foo
- };
- consume_ref(&foo);
- consume_move(foo);
- }
- // ============================================================================
- // Shared definitions.
- // ============================================================================
- #[derive(Debug, Default)]
- struct Foo {
- value: usize,
- }
- impl Foo {
- fn chain_move(mut self) -> Self {
- self.value += 1;
- self
- }
- fn chain_ref(&mut self) -> &mut Self {
- self.value += 1;
- self
- }
- }
- fn consume_move(foo: Foo) {
- println!("{:?}", foo);
- }
- fn consume_ref(foo: &Foo) {
- println!("{:?}", foo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement