Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I am just getting into rust myself - following from that 30 min article a few days ago.

From my understanding, the comments in a few of the examples are misleading. Author is stating things like "// mutable borrow occured" where there is no mutable borrow occuring. My understanding is that there is an implicit mutable borrow where the methods are being called (e.g. `original_owner.push('.');`) which is raising the errors

Can anyone with more experience confirm/deny that this is the case, as I want to be sure I am not misunderstanding this



You are correct. The type signature for push takes a mutable reference to self.

The code for a vector of i32s could look something like:

    impl Vec {
      pub fn push(&mut self, x:i32){
        // internal details
      }
    }


Many thanks. I think most of the confusion is to do with the comments, some of which the author has resolved so now my comment doesn't make much sense. But in the context of the original statement, thanks for your confirmation :)


Author here.

The "// mutable borrow occurred" was a typo. Fixed now


Thanks. Just a quick look through and it makes more sense now. Theres also a few places where you comment saying a borrow occured before the borrow occurs (in others the comment appears afterwards, as I would expect) - i.e. the comments are in the wrong place / inconsistently placed.

Obviously it doesnt affect the output of the code, but as a tutorial its probably better to correct that.

EDIT: further nitpicks, i would advise against calling the borrower the "borrowing owner", and other such terms - owner has a very specific meaning when it comes to memory management, etc.


Thanks for the feedback. I just quickly went through the code examples and tried to sanitise them as much as I can now. As soon as I have more free time on my hands, I will revisit and update the naming based on your feedback. Thanks!


No problem - thank you for sharing your progress.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: