1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#![allow(clippy::should_implement_trait)] /// Helper type to allow passing something that may potentially be owned, but could also be borrowed #[derive(Debug)] pub enum MaybeOwned<'a, T> { Owned(T), Borrowed(&'a T), } impl<T> MaybeOwned<'_, T> { /// Allows the borrowing of an owned value or passes out the borrowed value pub fn borrow(&self) -> &T { match self { MaybeOwned::Owned(v) => v, MaybeOwned::Borrowed(v) => v, } } }