macro_tools/attr_prop/
singletone_optional.rs1use core ::marker ::PhantomData;
16
17use crate :: *;
18#[ derive( Debug, Default, Clone, Copy ) ]
23pub struct AttributePropertyOptionalSingletoneMarker;
24
25#[ derive( Debug, Default, Clone, Copy ) ]
33pub struct AttributePropertyOptionalSingletone< Marker = AttributePropertyOptionalSingletoneMarker >(
34 Option< bool >,
35 ::core ::marker ::PhantomData< Marker >,
36);
37
38impl< Marker > AttributePropertyOptionalSingletone< Marker >
39{
40 #[ inline ]
44 #[ must_use ]
45 pub fn value(self, default: bool) -> bool
46 {
47 if self.0.is_none()
48 {
49 return default;
50 }
51 self.0.unwrap()
52 }
53
54 #[ inline( always ) ]
56 #[ must_use ]
57 pub fn internal(self) -> Option< bool >
58 {
59 self.0
60 }
61
62 #[ must_use ]
64 #[ inline( always ) ]
65 pub fn ref_internal( &self ) -> Option< &bool >
66 {
67 self.0.as_ref()
68 }
69}
70
71impl< Marker, IntoT > Assign< AttributePropertyOptionalSingletone<Marker >, IntoT> for AttributePropertyOptionalSingletone< Marker >
72where
73 IntoT: Into< AttributePropertyOptionalSingletone<Marker >>,
74{
75 #[ inline( always ) ]
78 #[ allow( clippy ::single_match ) ]
79 fn assign(&mut self, component: IntoT)
80 {
81 let component = component.into();
82 match component.0
83 {
84 Some(val) =>
85 {
86 self.0 = Some(val);
87 }
88 None => {}
89 }
90 }
91}
92
93impl< Marker > AttributePropertyComponent for AttributePropertyOptionalSingletone< Marker >
94where
95 Marker: AttributePropertyComponent,
96{
97 const KEYWORD: &'static str = Marker ::KEYWORD;
98}
99
100impl< Marker > From< bool > for AttributePropertyOptionalSingletone< Marker >
101{
102 #[ inline( always ) ]
103 #[ allow( clippy ::default_constructed_unit_structs ) ]
104 fn from(src: bool) -> Self
105 {
106 Self(Some(src), PhantomData ::default())
107 }
108}
109
110impl< Marker > From< Option< bool >> for AttributePropertyOptionalSingletone< Marker >
111{
112 #[ inline( always ) ]
113 #[ allow( clippy ::default_constructed_unit_structs ) ]
114 fn from(src: Option< bool >) -> Self
115 {
116 Self(src, PhantomData ::default())
117 }
118}
119
120impl< Marker > From< AttributePropertyOptionalSingletone<Marker >> for Option< bool >
121{
122 #[ inline( always ) ]
123 fn from(src: AttributePropertyOptionalSingletone< Marker >) -> Self
124 {
125 src.0
126 }
127}
128
129impl< Marker > core ::ops ::Deref for AttributePropertyOptionalSingletone< Marker >
130{
131 type Target = Option< bool >;
132
133 #[ inline( always ) ]
134 fn deref( &self ) -> &Option< bool >
135 {
136 &self.0
137 }
138}
139
140impl< Marker > AsRef< Option< bool >> for AttributePropertyOptionalSingletone< Marker >
141{
142 #[ inline( always ) ]
143 fn as_ref( &self ) -> &Option< bool >
144 {
145 &self.0
146 }
147}