On 26/05/2014 22:52, Patrick Walton wrote:
On 5/26/14 2:44 PM, Simon Sapin wrote:
Unlike C++, Rust does not have method overloading so the accessors are
much more verbose.
`nscoord ISize(WritingMode aWritingMode) const` overloaded with
`nscoord& ISize(WritingMode aWritingMode)` becomes
`get_i_size(&self, mode: WritingMode) -> T` and
`set_i_size(&mut self, mode: WritingMode, T)`.
The setter could be replaced with
`i_size_ref(&'a mut self, mode: WritingMode) -> &'a mut T`, but the
getter would still be needed so that reading does not require `&mut`. Or
perhaps we should have all three.

Is there a better way to do accessors in Rust?
Do we need the `get_` prefix? That is, could it just be `.isize()`?

(In general, I find that single-letter abbreviations read better when
squished up next to the word they go with, without underscores. Just
personal preference, I guess.)

I’m fine with that, but I’m more interested in the signature than the naming. That is, which of these (or others) to have, for each private field?

fn(&self) -> T
fn(&mut self, T)
fn(&'a mut self) -> &'a mut T

--
Simon Sapin
_______________________________________________
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo

Reply via email to