diff options
Diffstat (limited to 'src/util/mod.rs')
| -rw-r--r-- | src/util/mod.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/util/mod.rs b/src/util/mod.rs index d898f545..3bc13bac 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -11,7 +11,7 @@ pub use prehashed::Prehashed; use std::cmp::Ordering; use std::fmt::{self, Debug, Formatter}; -use std::ops::Range; +use std::ops::{Deref, Range}; use std::path::{Component, Path, PathBuf}; use std::sync::Arc; @@ -101,6 +101,31 @@ where } } +/// Either owned or shared. +pub enum MaybeShared<T> { + /// Owned data. + Owned(T), + /// Shared data. + Shared(Arc<T>), +} + +impl<T> AsRef<T> for MaybeShared<T> { + fn as_ref(&self) -> &T { + self + } +} + +impl<T> Deref for MaybeShared<T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + match self { + Self::Owned(owned) => owned, + Self::Shared(shared) => shared, + } + } +} + /// Additional methods for slices. pub trait SliceExt<T> { /// Split a slice into consecutive runs with the same key and yield for |
