we are not adding get_ keyword in the methods as there is no such bound check etc and there is a single thing that we can get from these methods.
so I think->
The get naming is used only when there is a single and obvious thing that could reasonably be gotten by a getter. written next to this example is contradicting it.
This struct has two things that could have getters: first and second[1]. If the struct only had one, then a get method might make sense.
pub struct S {
first: First,
}
impl S {
pub fn get(&self) -> &First {
&self.first
}
pub fn get_mut(&mut self) -> &mut First {
&mut self.first
}
}
I'd still go with first though, since that's clearer. Meanwhile, Cell is a wrapper around a single generic item, so there isn't anything to derive a name from, which is why it uses get.
The main reason Rust doesn't use the get prefix is that Rust allows structs to have members and methods with the same name.
Even if second doesn't have a getter, it's good to have a specific name so that people know which member is gettable and which isn't. âŠī¸