summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-04-19 13:54:04 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-19 13:54:04 +0200
commit255d4c620f39133b40a9132843781f2a620a6008 (patch)
treeacf95fdc671f2bb163d0b819b87e778bc7502d93 /src/util
parentf27f7a05ab24e57da99af9b4b96bab82bb31276a (diff)
Automatic frame merging
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mod.rs27
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