| minutes | 2 |
|---|
Getting an element from a collection or container.
impl <T> Vec<T> {
fn get(&self, index: usize) -> Option<&T> {...}
}
impl <T> OnceCell {
fn get(&self) -> Option<&T> {...}
}Details
- Gets are trivial, they get a value!Immutable by default.
Should not panic. May return an option or result, depending on the framework.
-
Not for fields!
For private fields you don't want users to have direct, assign a method with a more descriptive name (or the same name as the field) is preferred.