1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//!
//! Property of an attribute which simply wraps one of the standard `syn` types.
//!

use crate::*;
// use former_types::Assign;

/// Default marker for `AttributePropertySyn`.
/// Used if no marker is defined as parameter.
#[ derive( Debug, Default, Clone, Copy ) ]
pub struct AttributePropertySynMarker;

///
/// Property of an attribute which simply wraps one of the standard `syn` types.
///

#[ derive( Debug, Clone ) ]
pub struct AttributePropertySyn< T, Marker = AttributePropertySynMarker >( T, ::core::marker::PhantomData< Marker > )
where
  T : syn::parse::Parse + quote::ToTokens;

impl< T, Marker > AttributePropertySyn< T, Marker >
where
  T : syn::parse::Parse + quote::ToTokens,
{
  /// Just unwraps and returns the internal data.
  // #[ allow( dead_code ) ]
  #[ inline( always ) ]
  pub fn internal( self ) -> T
  {
    self.0
  }

  /// Returns a reference to the internal data.
  // #[ allow( dead_code ) ]
  #[ inline( always ) ]
  pub fn ref_internal( &self ) -> &T
  {
    &self.0
  }
}

impl< T, Marker, IntoT > Assign< AttributePropertySyn< T, Marker >, IntoT >
for AttributePropertySyn< T, Marker >
where
  T : syn::parse::Parse + quote::ToTokens,
  IntoT : Into< AttributePropertySyn< T, Marker > >,
{
  #[ inline( always ) ]
  fn assign( &mut self, component : IntoT )
  {
    *self = component.into();
  }
}

impl< T, Marker > AttributePropertyComponent for AttributePropertySyn< T, Marker >
where
  T : syn::parse::Parse + quote::ToTokens,
  Marker : AttributePropertyComponent,
{
  const KEYWORD : &'static str = Marker::KEYWORD;
}

impl< T, Marker > syn::parse::Parse for AttributePropertySyn< T, Marker >
where
  T : syn::parse::Parse + quote::ToTokens,
{
  fn parse( input : syn::parse::ParseStream< '_ > ) -> syn::Result< Self >
  {
    input.parse::< syn::Token![ = ] >()?;
    let value : T = input.parse()?;
    Ok( value.into() )
  }
}

impl< T, Marker > quote::ToTokens for AttributePropertySyn< T, Marker >
where
  T : syn::parse::Parse + quote::ToTokens,
{
  fn to_tokens( &self, tokens : &mut proc_macro2::TokenStream )
  {
    self.0.to_tokens( tokens );
  }
}

impl< T, Marker > core::ops::Deref for AttributePropertySyn< T, Marker >
where T : syn::parse::Parse + quote::ToTokens
{
  type Target = T;
  #[ inline( always ) ]
  fn deref( &self ) -> &T
  {
    &self.0
  }
}

impl< T, Marker > AsRef< T > for AttributePropertySyn< T, Marker >
where T : syn::parse::Parse + quote::ToTokens
{
  #[ inline( always ) ]
  fn as_ref( &self ) -> &T
  {
    &self.0
  }
}

impl< T, Marker > From< T > for AttributePropertySyn< T, Marker >
where T : syn::parse::Parse + quote::ToTokens
{
  #[ inline( always ) ]
  fn from( src : T ) -> Self
  {
    Self( src, Default::default() )
  }
}