@@ -17,12 +17,23 @@ lazy_static! {
17
17
}
18
18
```
19
19
20
- Metadata (such as doc comments) is allowed on each ref.
20
+ Attributes (including doc comments) are supported as well:
21
+
22
+ ```rust
23
+ # #[macro_use]
24
+ # extern crate lazy_static;
25
+ # fn main() {
26
+ lazy_static! {
27
+ /// This is an example for using doc comment attributes
28
+ static ref EXAMPLE: u8 = 42;
29
+ }
30
+ # }
31
+ ```
21
32
22
33
# Semantic
23
34
24
35
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
36
+ implements `Deref<TYPE>` and stores it in a static with name `NAME`. (Attributes end up
26
37
attaching to this type.)
27
38
28
39
On first deref, `EXPR` gets evaluated and stored internally, such that all further derefs
@@ -74,29 +85,34 @@ The `Deref` implementation uses a hidden static variable that is guarded by a at
74
85
#![ no_std]
75
86
76
87
#[ cfg( not( feature="nightly" ) ) ]
88
+ #[ doc( hidden) ]
77
89
pub mod lazy;
78
90
79
91
#[ cfg( all( feature="nightly" , not( feature="spin_no_std" ) ) ) ]
80
92
#[ path="nightly_lazy.rs" ]
93
+ #[ doc( hidden) ]
81
94
pub mod lazy;
82
95
83
96
#[ cfg( all( feature="nightly" , feature="spin_no_std" ) ) ]
84
97
#[ path="core_lazy.rs" ]
98
+ #[ doc( hidden) ]
85
99
pub mod lazy;
86
100
101
+ #[ doc( hidden) ]
87
102
pub use core:: ops:: Deref as __Deref;
88
103
89
104
#[ macro_export]
90
105
#[ cfg_attr( feature="nightly" , allow_internal_unstable) ]
91
- macro_rules! lazy_static {
106
+ #[ doc( hidden) ]
107
+ macro_rules! __lazy_static_internal {
92
108
( $( #[ $attr: meta] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
93
- lazy_static !( @PRIV , $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
109
+ __lazy_static_internal !( @PRIV , $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
94
110
} ;
95
111
( $( #[ $attr: meta] ) * pub static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
96
- lazy_static !( @PUB , $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
112
+ __lazy_static_internal !( @PUB , $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
97
113
} ;
98
114
( @$VIS: ident, $( #[ $attr: meta] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
99
- lazy_static !( @MAKE TY , $VIS, $( #[ $attr] ) * , $N) ;
115
+ __lazy_static_internal !( @MAKE TY , $VIS, $( #[ $attr] ) * , $N) ;
100
116
impl $crate:: __Deref for $N {
101
117
type Target = $T;
102
118
#[ allow( unsafe_code) ]
@@ -114,7 +130,7 @@ macro_rules! lazy_static {
114
130
}
115
131
}
116
132
}
117
- lazy_static !( $( $t) * ) ;
133
+ __lazy_static_internal !( $( $t) * ) ;
118
134
} ;
119
135
( @MAKE TY , PUB , $( #[ $attr: meta] ) * , $N: ident) => {
120
136
#[ allow( missing_copy_implementations) ]
@@ -136,3 +152,26 @@ macro_rules! lazy_static {
136
152
} ;
137
153
( ) => ( )
138
154
}
155
+
156
+ #[ macro_export]
157
+ #[ cfg_attr( feature="nightly" , allow_internal_unstable) ]
158
+ macro_rules! lazy_static {
159
+ ( $( #[ $attr: meta] ) * static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
160
+ __lazy_static_internal!( @PRIV , $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
161
+ } ;
162
+ ( $( #[ $attr: meta] ) * pub static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
163
+ __lazy_static_internal!( @PUB , $( #[ $attr] ) * static ref $N : $T = $e; $( $t) * ) ;
164
+ } ;
165
+ ( ) => ( )
166
+ }
167
+
168
+ /*
169
+ trait LazyStatic<T>: Deref<Target=T> {
170
+
171
+ }
172
+
173
+ ///
174
+ pub fn initialize<T>(lazy: &lazy::Lazy<T>) {
175
+
176
+ }
177
+ */
0 commit comments