summaryrefslogtreecommitdiffstats
path: root/vendor/rowan/src/cow_mut.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rowan/src/cow_mut.rs')
-rw-r--r--vendor/rowan/src/cow_mut.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/rowan/src/cow_mut.rs b/vendor/rowan/src/cow_mut.rs
new file mode 100644
index 000000000..c50e25b70
--- /dev/null
+++ b/vendor/rowan/src/cow_mut.rs
@@ -0,0 +1,30 @@
+#[derive(Debug)]
+pub(crate) enum CowMut<'a, T> {
+ Owned(T),
+ Borrowed(&'a mut T),
+}
+
+impl<T> std::ops::Deref for CowMut<'_, T> {
+ type Target = T;
+ fn deref(&self) -> &T {
+ match self {
+ CowMut::Owned(it) => it,
+ CowMut::Borrowed(it) => *it,
+ }
+ }
+}
+
+impl<T> std::ops::DerefMut for CowMut<'_, T> {
+ fn deref_mut(&mut self) -> &mut T {
+ match self {
+ CowMut::Owned(it) => it,
+ CowMut::Borrowed(it) => *it,
+ }
+ }
+}
+
+impl<T: Default> Default for CowMut<'_, T> {
+ fn default() -> Self {
+ CowMut::Owned(T::default())
+ }
+}