time/format_description/
borrowed_format_item.rs1#[cfg(feature = "alloc")]
4use alloc::string::String;
5#[cfg(feature = "alloc")]
6use core::fmt;
7
8use crate::error;
9use crate::format_description::Component;
10
11#[non_exhaustive]
13#[cfg_attr(not(feature = "alloc"), derive(Debug))]
14#[derive(#[automatically_derived]
impl<'a> ::core::clone::Clone for BorrowedFormatItem<'a> {
#[inline]
fn clone(&self) -> BorrowedFormatItem<'a> {
match self {
BorrowedFormatItem::Literal(__self_0) =>
BorrowedFormatItem::Literal(::core::clone::Clone::clone(__self_0)),
BorrowedFormatItem::Component(__self_0) =>
BorrowedFormatItem::Component(::core::clone::Clone::clone(__self_0)),
BorrowedFormatItem::Compound(__self_0) =>
BorrowedFormatItem::Compound(::core::clone::Clone::clone(__self_0)),
BorrowedFormatItem::Optional(__self_0) =>
BorrowedFormatItem::Optional(::core::clone::Clone::clone(__self_0)),
BorrowedFormatItem::First(__self_0) =>
BorrowedFormatItem::First(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, #[automatically_derived]
impl<'a> ::core::cmp::PartialEq for BorrowedFormatItem<'a> {
#[inline]
fn eq(&self, other: &BorrowedFormatItem<'a>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(BorrowedFormatItem::Literal(__self_0),
BorrowedFormatItem::Literal(__arg1_0)) =>
__self_0 == __arg1_0,
(BorrowedFormatItem::Component(__self_0),
BorrowedFormatItem::Component(__arg1_0)) =>
__self_0 == __arg1_0,
(BorrowedFormatItem::Compound(__self_0),
BorrowedFormatItem::Compound(__arg1_0)) =>
__self_0 == __arg1_0,
(BorrowedFormatItem::Optional(__self_0),
BorrowedFormatItem::Optional(__arg1_0)) =>
__self_0 == __arg1_0,
(BorrowedFormatItem::First(__self_0),
BorrowedFormatItem::First(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl<'a> ::core::cmp::Eq for BorrowedFormatItem<'a> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<&'a [u8]>;
let _: ::core::cmp::AssertParamIsEq<Component>;
let _: ::core::cmp::AssertParamIsEq<&'a [Self]>;
let _: ::core::cmp::AssertParamIsEq<&'a Self>;
let _: ::core::cmp::AssertParamIsEq<&'a [Self]>;
}
}Eq)]
15pub enum BorrowedFormatItem<'a> {
16 Literal(&'a [u8]),
21 Component(Component),
23 Compound(&'a [Self]),
26 Optional(&'a Self),
31 First(&'a [Self]),
35}
36
37#[cfg(feature = "alloc")]
38impl fmt::Debug for BorrowedFormatItem<'_> {
39 #[inline]
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 Self::Literal(literal) => f.write_str(&String::from_utf8_lossy(literal)),
43 Self::Component(component) => component.fmt(f),
44 Self::Compound(compound) => compound.fmt(f),
45 Self::Optional(item) => f.debug_tuple("Optional").field(item).finish(),
46 Self::First(items) => f.debug_tuple("First").field(items).finish(),
47 }
48 }
49}
50
51impl From<Component> for BorrowedFormatItem<'_> {
52 #[inline]
53 fn from(component: Component) -> Self {
54 Self::Component(component)
55 }
56}
57
58impl TryFrom<BorrowedFormatItem<'_>> for Component {
59 type Error = error::DifferentVariant;
60
61 #[inline]
62 fn try_from(value: BorrowedFormatItem<'_>) -> Result<Self, Self::Error> {
63 match value {
64 BorrowedFormatItem::Component(component) => Ok(component),
65 _ => Err(error::DifferentVariant),
66 }
67 }
68}
69
70impl<'a> From<&'a [BorrowedFormatItem<'_>]> for BorrowedFormatItem<'a> {
71 #[inline]
72 fn from(items: &'a [BorrowedFormatItem<'_>]) -> Self {
73 Self::Compound(items)
74 }
75}
76
77impl<'a> TryFrom<BorrowedFormatItem<'a>> for &[BorrowedFormatItem<'a>] {
78 type Error = error::DifferentVariant;
79
80 #[inline]
81 fn try_from(value: BorrowedFormatItem<'a>) -> Result<Self, Self::Error> {
82 match value {
83 BorrowedFormatItem::Compound(items) => Ok(items),
84 _ => Err(error::DifferentVariant),
85 }
86 }
87}
88
89impl PartialEq<Component> for BorrowedFormatItem<'_> {
90 #[inline]
91 fn eq(&self, rhs: &Component) -> bool {
92 #[allow(non_exhaustive_omitted_patterns)] match self {
Self::Component(component) if component == rhs => true,
_ => false,
}matches!(self, Self::Component(component) if component == rhs)
93 }
94}
95
96impl PartialEq<BorrowedFormatItem<'_>> for Component {
97 #[inline]
98 fn eq(&self, rhs: &BorrowedFormatItem<'_>) -> bool {
99 rhs == self
100 }
101}
102
103impl PartialEq<&[Self]> for BorrowedFormatItem<'_> {
104 #[inline]
105 fn eq(&self, rhs: &&[Self]) -> bool {
106 #[allow(non_exhaustive_omitted_patterns)] match self {
Self::Compound(compound) if compound == rhs => true,
_ => false,
}matches!(self, Self::Compound(compound) if compound == rhs)
107 }
108}
109
110impl PartialEq<BorrowedFormatItem<'_>> for &[BorrowedFormatItem<'_>] {
111 #[inline]
112 fn eq(&self, rhs: &BorrowedFormatItem<'_>) -> bool {
113 rhs == self
114 }
115}