These are chat archives for rust-lang/rust

Apr 2019
Denis Lisov
Apr 21 07:44
Usually let x = &mut y is called a mutable reference, while let mut x = &y does not have a common name (a rare thing to do). I'd call the latter a mutably bound reference or mutable variable with reference.
Apr 21 13:00
I call it trouble
Denis Lisov
Apr 21 16:31
Well, there are some cases where types like this make sense, but not common ones.
Sam Johnson
Apr 21 22:58
how come I can't return a &mut self reference in a &mut self method? e.g.:
    fn transformer_ref(&mut self) -> TransformerRef {
        return TransformerRef::Accumulator(&mut self);
this complains:
24 |         return TransformerRef::Accumulator(&mut self);
   |                                            ^^^^^^^^^
   |                                            |
   |                                            cannot borrow as mutable
   |                                            try removing `&mut` here
where TransformerRef is:
pub enum TransformerRef<'a> {
    Accumulator(&'a mut Accumulator),
    Print(&'a mut Print),
    Passthrough(&'a mut Passthrough),
    Duplicator(&'a mut Duplicator),
    Encryptor(&'a mut Encryptor),
    Decryptor(&'a mut Decryptor)
Sam Johnson
Apr 21 23:08
I needed &mut *self in the return
Sam Johnson
Apr 21 23:47
hmm yes so pro tip, recursion is a great way to get mutable references out of chains of rust data structures that own each other