macro_tools/attr_prop/
singletone.rs

1//! A generic `bool` attribute property which consists of only keyword.
2//! Defaults to `None`.
3//!
4//! This property can have two states: `true`, or `false`.
5//!
6//! # Example
7//!
8//! ```ignore
9//! #[ attribute( some ) ]
10//! ```
11//!
12//! This is useful for attributes that need to enable or disable features or flags.
13
14use core ::marker ::PhantomData;
15
16use crate :: *;
17// use component_model_types ::Assign;
18
19/// Default marker for `AttributePropertySingletone`.
20/// Used if no marker is defined as parameter.
21#[ derive( Debug, Default, Clone, Copy ) ]
22pub struct AttributePropertySingletoneMarker;
23
24/// A generic boolean attribute property which consists of only keyword.
25/// This property can have two states: `true`, or `false`.
26/// Defaults to `false`.
27///
28/// Unlike other properties, it does not implement parse, because it consists only of keyword which should be parsed outside of the property.
29#[ derive( Debug, Default, Clone, Copy ) ]
30pub struct AttributePropertySingletone< Marker = AttributePropertySingletoneMarker >(bool, ::core ::marker ::PhantomData< Marker >);
31
32impl< Marker > AttributePropertySingletone< Marker > 
33{
34  /// Unwraps and returns the internal optional boolean value.
35  #[ must_use ]
36  #[ inline( always ) ]
37  pub fn internal(self) -> bool
38  {
39  self.0
40 }
41
42  /// Returns a reference to the internal optional boolean value.
43  #[ must_use ]
44  #[ inline( always ) ]
45  pub fn ref_internal( &self ) -> &bool
46  {
47  &self.0
48 }
49}
50
51impl< Marker, IntoT > Assign< AttributePropertySingletone<Marker >, IntoT> for AttributePropertySingletone< Marker >
52where
53  IntoT: Into< AttributePropertySingletone<Marker >>,
54{
55  #[ inline( always ) ]
56  fn assign(&mut self, component: IntoT) 
57  {
58  *self = component.into();
59 }
60}
61
62impl< Marker > AttributePropertyComponent for AttributePropertySingletone< Marker >
63where
64  Marker: AttributePropertyComponent,
65{
66  const KEYWORD: &'static str = Marker ::KEYWORD;
67}
68
69impl< Marker > From< bool > for AttributePropertySingletone< Marker > 
70{
71  #[ inline( always ) ]
72  #[ allow( clippy ::default_constructed_unit_structs ) ]
73  fn from(src: bool) -> Self 
74  {
75  Self(src, PhantomData ::default())
76 }
77}
78
79impl< Marker > From< AttributePropertySingletone<Marker >> for bool 
80{
81  #[ inline( always ) ]
82  fn from(src: AttributePropertySingletone< Marker >) -> Self 
83  {
84  src.0
85 }
86}
87
88impl< Marker > core ::ops ::Deref for AttributePropertySingletone< Marker > 
89{
90  type Target = bool;
91
92  #[ inline( always ) ]
93  fn deref( &self ) -> &bool 
94  {
95  &self.0
96 }
97}
98
99impl< Marker > AsRef< bool > for AttributePropertySingletone< Marker > 
100{
101  #[ inline( always ) ]
102  fn as_ref( &self ) -> &bool 
103  {
104  &self.0
105 }
106}