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

Yes, it works, but feels unnatural. I also don't like the possibility (quite remote, I admit) that the function gets called with a field from another instance.


The latter case should be impossible if the method is private?


In Rust, privacy isn't enforced like that. Private just means that things outside the module can't access them. There's no concept of privacy at the instance level.


Yes. So don't make any methods that could potentially be passed incorrect arguments public.


That still doesn't preclude the possibility that within the module the function gets called with a field from another instance. I think the idea is that by making it a method that just takes a reference to self, it's impossible to accidentally mutate a field on a different instance, while taking a reference to the field itself doesn't prevent the programmer from accidentally calling it with the wrong instance of the field.




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

Search: