scsys_core/cont/traits/get.rs
1/*
2 appellation: get <module>
3 authors: @FL03
4*/
5
6/// [`Get`] defines an interface for entities that can be accessed by a key; the design is
7/// similar to the [`Index`](core::ops::Index) trait in the standard library, however, uses the
8/// [`Borrow`](core::borrow::Borrow) trait to allow for more flexible key types.
9pub trait Get<T> {
10 type Key;
11 /// returns a reference to the element at the specified index.
12 fn get<Q>(&self, index: Q) -> Option<&T>
13 where
14 Q: core::borrow::Borrow<Self::Key>;
15}
16/// [`GetMut`] defines an interface for entities that can be accessed by a key; the design
17/// is similar to the [`IndexMut`](core::ops::IndexMut) trait in the standard library
18pub trait GetMut<T>: Get<T> {
19 /// returns a mutable reference to the element at the specified index.
20 fn get_mut<Q>(&mut self, index: Q) -> Option<&mut T>
21 where
22 Q: core::borrow::Borrow<Self::Key>;
23}