Why doesn't I need the `mut` keyword

Following that up a bit more, you can also do this:

impl PDFDocument {
    fn modify(&mut self) { /* ... */ }
}

fn main() {
    let document = PDFDocument::default();
    let mut document = document;
    document.modify();
}

So similarly you could have wrote

impl PDFDocument {
    fn save(self) {
        // (Different name because you can't shadow `self` specifically)
        let mut self_ = self;
        // ...
    }
}

So (a) changing mutability when moving is a general thing and not a function call specific thing, and (b) the signature doesn't even actually tell you if the argument is modified in the body or not.

3 Likes