@@ -17,10 +17,13 @@ lazy_static! {
17
17
}
18
18
```
19
19
20
+ Metadata (such as doc comments) is allowed on each ref.
21
+
20
22
# Semantic
21
23
22
- For a given `static ref NAME: TYPE = EXPR;`, the macro generates a
23
- unique type that implements `Deref<TYPE>` and stores it in a static with name `NAME`.
24
+ For a given `static ref NAME: TYPE = EXPR;`, the macro generates a unique type that
25
+ implements `Deref<TYPE>` and stores it in a static with name `NAME`. (Metadata ends up
26
+ attaching to this type.)
24
27
25
28
On first deref, `EXPR` gets evaluated and stored internally, such that all further derefs
26
29
can return a reference to the same object.
@@ -72,14 +75,14 @@ define uninitialized `static mut` values.
72
75
73
76
#[ macro_export]
74
77
macro_rules! lazy_static {
75
- ( static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
76
- lazy_static!( PRIV static ref $N : $T = $e; $( $t) * ) ;
78
+ ( $ ( # [ $attr : meta ] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
79
+ lazy_static!( PRIV , $ ( # [ $attr ] ) * static ref $N : $T = $e; $( $t) * ) ;
77
80
} ;
78
- ( pub static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
79
- lazy_static!( PUB static ref $N : $T = $e; $( $t) * ) ;
81
+ ( $ ( # [ $attr : meta ] ) * pub static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
82
+ lazy_static!( PUB , $ ( # [ $attr ] ) * static ref $N : $T = $e; $( $t) * ) ;
80
83
} ;
81
- ( $VIS: ident static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
82
- lazy_static!( MAKE TY $VIS $N) ;
84
+ ( $VIS: ident, $ ( # [ $attr : meta ] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
85
+ lazy_static!( MAKE TY , $VIS, $ ( # [ $attr ] ) * , $N) ;
83
86
impl :: std:: ops:: Deref for $N {
84
87
type Target = $T;
85
88
fn deref<' a>( & ' a self ) -> & ' a $T {
@@ -106,18 +109,22 @@ macro_rules! lazy_static {
106
109
}
107
110
lazy_static!( $( $t) * ) ;
108
111
} ;
109
- ( MAKE TY PUB $N: ident) => {
112
+ ( MAKE TY , PUB , $ ( # [ $attr : meta ] ) * , $N: ident) => {
110
113
#[ allow( missing_copy_implementations) ]
111
114
#[ allow( non_camel_case_types) ]
112
115
#[ allow( dead_code) ]
116
+ $( #[ $attr] ) *
113
117
pub struct $N { __private_field: ( ) }
118
+ #[ doc( hidden) ]
114
119
pub static $N: $N = $N { __private_field: ( ) } ;
115
120
} ;
116
- ( MAKE TY PRIV $N: ident) => {
121
+ ( MAKE TY , PRIV , $ ( # [ $attr : meta ] ) * , $N: ident) => {
117
122
#[ allow( missing_copy_implementations) ]
118
123
#[ allow( non_camel_case_types) ]
119
124
#[ allow( dead_code) ]
125
+ $( #[ $attr] ) *
120
126
struct $N { __private_field: ( ) }
127
+ #[ doc( hidden) ]
121
128
static $N: $N = $N { __private_field: ( ) } ;
122
129
} ;
123
130
( ) => ( )
0 commit comments