1#[derive(Debug)]
2pub(crate) enum CowMut<'a, T> {
3 Owned(T),
4 Borrowed(&'a mut T),
5}
6
7impl<T> std::ops::Deref for CowMut<'_, T> {
8 type Target = T;
9 fn deref(&self) -> &T {
10 match self {
11 CowMut::Owned(it: &T) => it,
12 CowMut::Borrowed(it: &&mut T) => *it,
13 }
14 }
15}
16
17impl<T> std::ops::DerefMut for CowMut<'_, T> {
18 fn deref_mut(&mut self) -> &mut T {
19 match self {
20 CowMut::Owned(it: &mut T) => it,
21 CowMut::Borrowed(it: &mut &mut T) => *it,
22 }
23 }
24}
25
26impl<T: Default> Default for CowMut<'_, T> {
27 fn default() -> Self {
28 CowMut::Owned(T::default())
29 }
30}
31