News for hackers. Stuff that matters.
Re:Async-await on stable Rust by entropicdrifter on Thursday November 07, 2019 @10:30AM (#21474032)
Couldn't you just pass in the (other) borrowed field as an argument for the function? If you need it to work without adding the argument when called outside of the class, you could overload it with a version that borrows the field and passes it to the version that takes the field as an argument, right?

I'm newish to Rust, so this is just an intuitive guess. Please let me know if I'm wrong.

Re:Async-await on stable Rust by dunkelheit on Thursday November 07, 2019 @12:15PM (#21475053)
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.
Re:Async-await on stable Rust by esotericn on Thursday November 07, 2019 @01:25PM (#21475812)
The latter case should be impossible if the method is private?
Re:Async-await on stable Rust by saghm on Thursday November 07, 2019 @09:49PM (#21479601)
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.
Re:Async-await on stable Rust by esotericn on Friday November 08, 2019 @05:37AM (#21481157)
Yes. So don't make any methods that could potentially be passed incorrect arguments public.
Re:Async-await on stable Rust by saghm on Friday November 08, 2019 @11:46AM (#21483974)
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.
Re:Async-await on stable Rust by Rusky on Thursday November 07, 2019 @11:15AM (#21474498)
Yes, that's the usual workaround.