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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#[cfg(feature = "std")]
use std::{ffi::OsStr, path::Path};

use crate::{Cow, Dairy};

impl<'a, T> AsRef<T> for Cow<'a, T>
where
    T: ?Sized + Dairy<'a>,
{
    #[inline]
    fn as_ref(&self) -> &T {
        self.make_ref()
    }
}

////////////////////////////////////////////////////////////////////////////////
// Cow<str>
////////////////////////////////////////////////////////////////////////////////

impl AsRef<[u8]> for Cow<'_, str> {
    #[inline]
    fn as_ref(&self) -> &[u8] {
        self.make_ref().as_ref()
    }
}

#[cfg(feature = "std")]
impl AsRef<OsStr> for Cow<'_, str> {
    #[inline]
    fn as_ref(&self) -> &OsStr {
        self.make_ref().as_ref()
    }
}

#[cfg(feature = "std")]
impl AsRef<Path> for Cow<'_, str> {
    #[inline]
    fn as_ref(&self) -> &Path {
        self.make_ref().as_ref()
    }
}

////////////////////////////////////////////////////////////////////////////////
// Cow<OsStr>
////////////////////////////////////////////////////////////////////////////////

#[cfg(feature = "std")]
impl AsRef<Path> for Cow<'_, OsStr> {
    #[inline]
    fn as_ref(&self) -> &Path {
        self.make_ref().as_ref()
    }
}

////////////////////////////////////////////////////////////////////////////////
// Cow<Path>
////////////////////////////////////////////////////////////////////////////////

#[cfg(feature = "std")]
impl AsRef<OsStr> for Cow<'_, Path> {
    #[inline]
    fn as_ref(&self) -> &OsStr {
        self.make_ref().as_ref()
    }
}