orx_self_or/
self_or_ref.rs

1use crate::sealed::Sealed;
2
3/// A representation of an instance of a type that is either the instance itself,
4/// or a shared reference to the instance.
5///
6/// Notice that this common representation:
7/// * is capable of creating shared references through `get_ref` method;
8/// * however, it cannot create mutable references.
9pub trait SoR<T>: Sealed {
10    /// Returns a reference to self.
11    fn get_ref(&self) -> &T;
12}
13
14impl<T> SoR<T> for T {
15    #[inline(always)]
16    fn get_ref(&self) -> &T {
17        self
18    }
19}
20
21impl<T> SoR<T> for &T {
22    #[inline(always)]
23    fn get_ref(&self) -> &T {
24        self
25    }
26}