@@ -8,12 +8,12 @@ as well as anything that requires function calls to be computed.
88
99# Syntax
1010
11- ```rust
11+ ```ignore
1212lazy_static! {
13- static ref NAME_1: TYPE_1 = EXPR_1;
14- static ref NAME_2: TYPE_2 = EXPR_2;
13+ [pub] static ref NAME_1: TYPE_1 = EXPR_1;
14+ [pub] static ref NAME_2: TYPE_2 = EXPR_2;
1515 ...
16- static ref NAME_N: TYPE_N = EXPR_N;
16+ [pub] static ref NAME_N: TYPE_N = EXPR_N;
1717}
1818```
1919
@@ -77,32 +77,47 @@ define uninitialized `static mut` values.
7777
7878#[ macro_export]
7979macro_rules! lazy_static {
80- ( $( static ref $N: ident : $T: ty = $e: expr; ) * ) => {
81- $(
82- #[ allow( non_camel_case_types) ]
83- #[ allow( dead_code) ]
84- struct $N { __private_field: ( ) }
85- static $N: $N = $N { __private_field: ( ) } ;
86- impl Deref <$T> for $N {
87- fn deref<' a>( & ' a self ) -> & ' a $T {
88- use std:: sync:: { Once , ONCE_INIT } ;
89- use std:: mem:: transmute;
90-
91- #[ inline( always) ]
92- fn require_sync<T : Sync >( _: & T ) { }
93-
94- unsafe {
95- static mut s: * const $T = 0 as * const $T;
96- static mut ONCE : Once = ONCE_INIT ;
97- ONCE . doit( || {
98- s = transmute:: <Box <$T>, * const $T>( box( ) ( $e) ) ;
99- } ) ;
100- let static_ref = & * s;
101- require_sync( static_ref) ;
102- static_ref
103- }
80+ ( static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
81+ lazy_static!( PRIV static ref $N : $T = $e; $( $t) * )
82+ } ;
83+ ( pub static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
84+ lazy_static!( PUB static ref $N : $T = $e; $( $t) * )
85+ } ;
86+ ( $VIS: ident static ref $N: ident : $T: ty = $e: expr; $( $t: tt) * ) => {
87+ lazy_static!( MAKE TY $VIS $N)
88+ impl Deref <$T> for $N {
89+ fn deref<' a>( & ' a self ) -> & ' a $T {
90+ use std:: sync:: { Once , ONCE_INIT } ;
91+ use std:: mem:: transmute;
92+
93+ #[ inline( always) ]
94+ fn require_sync<T : Sync >( _: & T ) { }
95+
96+ unsafe {
97+ static mut s: * const $T = 0 as * const $T;
98+ static mut ONCE : Once = ONCE_INIT ;
99+ ONCE . doit( || {
100+ s = transmute:: <Box <$T>, * const $T>( box( ) ( $e) ) ;
101+ } ) ;
102+ let static_ref = & * s;
103+ require_sync( static_ref) ;
104+ static_ref
104105 }
105106 }
106- ) *
107- }
107+ }
108+ lazy_static!( $( $t) * )
109+ } ;
110+ ( MAKE TY PUB $N: ident) => {
111+ #[ allow( non_camel_case_types) ]
112+ #[ allow( dead_code) ]
113+ pub struct $N { __private_field: ( ) }
114+ pub static $N: $N = $N { __private_field: ( ) } ;
115+ } ;
116+ ( MAKE TY PRIV $N: ident) => {
117+ #[ allow( non_camel_case_types) ]
118+ #[ allow( dead_code) ]
119+ struct $N { __private_field: ( ) }
120+ static $N: $N = $N { __private_field: ( ) } ;
121+ } ;
122+ ( ) => ( )
108123}
0 commit comments