1//! <https://github.com/rust-analyzer/rowan/blob/v0.16.1/src/cow_mut.rs>
2//!
3//! This module provides a `CowMut` type, which is a mutable version of `Cow`.
4//! Although it is strange that we can have a `CowMut`, because it should "copy
5//! on write", we also don't love the `Cow` API and use `Cow` without even
6//! touching its `DerefMut` feature.
78/// A mutable version of [Cow][`std::borrow::Cow`].
9#[derive(Debug)]
10pub enum CowMut<'a, T> {
11/// An owned data.
12Owned(T),
13/// A borrowed mut data.
14Borrowed(&'a mut T),
15}
1617impl<T> std::ops::Deref for CowMut<'_, T> {
18type Target = T;
19fn deref(&self) -> &T {
20match self {
21 CowMut::Owned(it) => it,
22 CowMut::Borrowed(it) => it,
23 }
24 }
25}
2627impl<T> std::ops::DerefMut for CowMut<'_, T> {
28fn deref_mut(&mut self) -> &mut T {
29match self {
30 CowMut::Owned(it) => it,
31 CowMut::Borrowed(it) => it,
32 }
33 }
34}
3536impl<T: Default> Default for CowMut<'_, T> {
37fn default() -> Self {
38 CowMut::Owned(T::default())
39 }
40}