1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::{AsIs, BorrowIs, Is, IsCow, Owned, ToOwned};
use alloc::borrow::Cow;
use core::borrow::Borrow;

impl<T: ?Sized + ToOwned> BorrowIs for Cow<'_, T>
where
    T: alloc::borrow::ToOwned<Owned = Owned<T>>,
{
    type Is = T;

    fn borrow_or_clone<B: ?Sized>(&self) -> IsCow<'_, B>
    where
        T: Borrow<B>,
        B: ToOwned<Owned = Owned<T>>,
    {
        (**self).borrow_or_clone()
    }
}

impl<T: ?Sized + ToOwned> AsIs for Cow<'_, T>
where
    T: alloc::borrow::ToOwned<Owned = Owned<T>>,
{
    fn as_is<'a>(self) -> Is<'a, T>
    where
        Self: 'a,
    {
        match self {
            Cow::Owned(x) => Is::Owned(x),
            Cow::Borrowed(x) => Is::Borrowed(x),
        }
    }
}