1#[derive(#[automatically_derived]impl<'a, T: ::core::clone::Clone> ::core::clone::Clone
for DumbCow<'a, T> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
match self {
Self::Owned(__self_0) =>
DumbCow::Owned(::core::clone::Clone::clone(__self_0)),
Self::Borrowed(__self_0) =>
DumbCow::Borrowed(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, #[automatically_derived]impl<'a, T: ::core::fmt::Debug> ::core::fmt::Debug for
DumbCow<'a, T> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Owned(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Owned",
&__self_0),
Self::Borrowed(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Borrowed", &__self_0),
}
}
}Debug)]
12pub(crate) enum DumbCow<'a, T> {
13 Owned(T),
14 Borrowed(&'a T),
15}
16
17impl<'a, T> DumbCow<'a, T> {
18 pub(crate) fn borrowed(&self) -> DumbCow<'_, T> {
19 match *self {
20 DumbCow::Owned(ref this) => DumbCow::Borrowed(this),
21 DumbCow::Borrowed(ref this) => DumbCow::Borrowed(this),
22 }
23 }
24}
25
26impl<'a, T> core::ops::Deref for DumbCow<'a, T> {
27 type Target = T;
28 fn deref(&self) -> &T {
29 match *self {
30 DumbCow::Owned(ref t) => t,
31 DumbCow::Borrowed(t) => t,
32 }
33 }
34}
35
36impl<'a, T: core::fmt::Display> core::fmt::Display for DumbCow<'a, T> {
37 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
38 core::fmt::Display::fmt(core::ops::Deref::deref(self), f)
39 }
40}
41
42#[derive(#[automatically_derived]impl<'a> ::core::clone::Clone for StringCow<'a> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
match self {
Self::Owned(__self_0) =>
StringCow::Owned(::core::clone::Clone::clone(__self_0)),
Self::Borrowed(__self_0) =>
StringCow::Borrowed(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, #[automatically_derived]impl<'a> ::core::fmt::Debug for StringCow<'a> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Owned(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Owned",
&__self_0),
Self::Borrowed(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Borrowed", &__self_0),
}
}
}Debug, #[automatically_derived]impl<'a> ::core::cmp::Eq for StringCow<'a> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<alloc::string::String>;
let _: ::core::cmp::AssertParamIsEq<&'a str>;
}
}Eq, #[automatically_derived]impl<'a> ::core::hash::Hash for StringCow<'a> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Owned(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Borrowed(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash, #[automatically_derived]impl<'a> ::core::marker::StructuralPartialEq for
StringCow<'a> {
}
#[automatically_derived]impl<'a> ::core::cmp::PartialEq for StringCow<'a> {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Owned(__self_0), Self::Owned(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Borrowed(__self_0), Self::Borrowed(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl<'a> ::core::cmp::PartialOrd for StringCow<'a> {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl<'a> ::core::cmp::Ord for StringCow<'a> {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
match (self, other) {
(Self::Owned(__self_0), Self::Owned(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(Self::Borrowed(__self_0), Self::Borrowed(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
_ =>
::core::cmp::Ord::cmp(&::core::intrinsics::discriminant_value(self),
&::core::intrinsics::discriminant_value(other)),
}
}
}Ord)]
46pub(crate) enum StringCow<'a> {
47 #[cfg(feature = "alloc")]
48 Owned(alloc::string::String),
49 Borrowed(&'a str),
50}
51
52impl<'a> StringCow<'a> {
53 pub(crate) fn as_str<'s>(&'s self) -> &'s str {
59 match *self {
60 #[cfg(feature = "alloc")]
61 StringCow::Owned(ref s) => s,
62 StringCow::Borrowed(s) => s,
63 }
64 }
65
66 #[cfg(feature = "alloc")]
70 pub(crate) fn into_owned(self) -> StringCow<'static> {
71 use alloc::string::ToString;
72
73 match self {
74 StringCow::Owned(string) => StringCow::Owned(string),
75 StringCow::Borrowed(string) => {
76 StringCow::Owned(string.to_string())
77 }
78 }
79 }
80}
81
82impl<'a> core::ops::Deref for StringCow<'a> {
83 type Target = str;
84 fn deref(&self) -> &str {
85 self.as_str()
86 }
87}
88
89impl<'a> core::fmt::Display for StringCow<'a> {
90 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
91 core::fmt::Display::fmt(self.as_str(), f)
92 }
93}
94
95#[cfg(feature = "alloc")]
96impl From<alloc::string::String> for StringCow<'static> {
97 fn from(string: alloc::string::String) -> StringCow<'static> {
98 StringCow::Owned(string)
99 }
100}
101
102impl<'a> From<&'a str> for StringCow<'a> {
103 fn from(string: &'a str) -> StringCow<'a> {
104 StringCow::Borrowed(string)
105 }
106}