Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 592 Bytes

File metadata and controls

31 lines (21 loc) · 592 Bytes
minutes 2

get: Borrow an Element

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.