Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- // Try to pass the result of `chain_ref` into `consume_move`.
- consume_move(Foo::default().chain_ref().chain_ref());
- // NOTE: You can pass the result of `chain_move` to `consume_ref`, but you
- // can't pass the result of `chain_ref` to `consume_move`.
- consume_ref(&Foo::default().chain_move().chain_move());
- // consume_move(Foo::default().chain_ref().chain_ref()); // Doesn't compile.
- }
- // ============================================================================
- // 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