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#[ allow( clippy::wildcard_imports ) ]
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 >
31(
32  bool,
33  ::core::marker::PhantomData< Marker >,
34);
35
36impl< Marker > AttributePropertySingletone< Marker >
37{
38
39  /// Unwraps and returns the internal optional boolean value.
40  #[ must_use ]
41  #[ inline( always ) ]
42  pub fn internal( self ) -> bool
43  {
44    self.0
45  }
46
47  /// Returns a reference to the internal optional boolean value.
48  #[ must_use ]
49  #[ inline( always ) ]
50  pub fn ref_internal( &self ) -> &bool
51  {
52    &self.0
53  }
54
55}
56
57impl< Marker, IntoT > Assign< AttributePropertySingletone< Marker >, IntoT >
58for AttributePropertySingletone< Marker >
59where
60  IntoT : Into< AttributePropertySingletone< Marker > >,
61{
62  #[ inline( always ) ]
63  fn assign( &mut self, component : IntoT )
64  {
65    *self = component.into();
66  }
67}
68
69impl< Marker > AttributePropertyComponent for AttributePropertySingletone< Marker >
70where
71  Marker : AttributePropertyComponent,
72{
73  const KEYWORD : &'static str = Marker::KEYWORD;
74}
75
76impl< Marker > From< bool > for AttributePropertySingletone< Marker >
77{
78  #[ inline( always ) ]
79  #[ allow( clippy::default_constructed_unit_structs ) ]
80  fn from( src : bool ) -> Self
81  {
82    Self( src, PhantomData::default() )
83  }
84}
85
86impl< Marker > From< AttributePropertySingletone< Marker > > for bool
87{
88  #[ inline( always ) ]
89  fn from( src : AttributePropertySingletone< Marker > ) -> Self
90  {
91    src.0
92  }
93}
94
95impl< Marker > core::ops::Deref for AttributePropertySingletone< Marker >
96{
97  type Target = bool;
98
99  #[ inline( always ) ]
100  fn deref( &self ) -> &bool
101  {
102    &self.0
103  }
104}
105
106impl< Marker > AsRef< bool > for AttributePropertySingletone< Marker >
107{
108  #[ inline( always ) ]
109  fn as_ref( &self ) -> &bool
110  {
111    &self.0
112  }
113}