Skip to content

Commit 4ff1fe2

Browse files
committed
fix visibility
1 parent 7396e5c commit 4ff1fe2

File tree

9 files changed

+167
-54
lines changed

9 files changed

+167
-54
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lazy-static-include"
3-
version = "3.1.4"
3+
version = "3.2.0"
44
authors = ["Magic Len <len@magiclen.org>"]
55
edition = "2021"
66
rust-version = "1.56"

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ The paths used for `lazy_static_include_bytes` and `lazy_static_include_str` are
2020
## Examples
2121

2222
```rust
23-
#[macro_use] extern crate lazy_static_include;
23+
use lazy_static_include::*;
2424

2525
lazy_static_include_str! {
2626
/// doc
2727
TEST => "data/test.txt",
28+
}
29+
30+
lazy_static_include_str! {
2831
/// doc
2932
pub TEST2 => ("data", "test-2.txt"),
3033
}
@@ -34,11 +37,14 @@ assert_eq!("Some text...", TEST2);
3437
```
3538

3639
```rust
37-
#[macro_use] extern crate lazy_static_include;
40+
use lazy_static_include::*;
3841

3942
lazy_static_include_bytes! {
4043
/// doc
4144
TEST => "data/test.txt",
45+
}
46+
47+
lazy_static_include_bytes! {
4248
/// doc
4349
pub TEST2 => ("data", "test-2.txt"),
4450
}
@@ -50,7 +56,7 @@ assert_eq!("Some text...".as_bytes(), TEST2);
5056
You should notice that the value created from `lazy_static_include_bytes` and `lazy_static_include_str` macros isn't equal to `&'static [u8]` or `&'static str`. If you want to get an exact `&'static [u8]` or `&'static str` reference, you can **dereference** the value.
5157

5258
```rust
53-
#[macro_use] extern crate lazy_static_include;
59+
use lazy_static_include::*;
5460

5561
lazy_static_include_bytes! {
5662
/// doc
@@ -60,6 +66,8 @@ lazy_static_include_bytes! {
6066
let data: &'static [u8] = *TEST;
6167
```
6268

69+
Also, private items (without `pub`) and public items (with `pub*`) cannot be put together.
70+
6371
## Include Array
6472

6573
There is a special macro `lazy_static_include_array` which can include arrays from files.
@@ -71,11 +79,14 @@ Be careful when you distribute your program.
7179
The paths used for `lazy_static_include_array` are relative to **CARGO_MANIFEST_DIR**.
7280

7381
```rust
74-
#[macro_use] extern crate lazy_static_include;
82+
use lazy_static_include::*;
7583

7684
lazy_static_include_array! {
7785
/// doc
7886
TEST: [u64; 5] => "data/u64_array.txt",
87+
}
88+
89+
lazy_static_include_array! {
7990
/// doc
8091
pub TEST2: [&'static str; 3] => ("data", "string_array.txt")
8192
}

src/lib.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ The paths used for `lazy_static_include_bytes` and `lazy_static_include_str` are
1818
## Examples
1919
2020
```rust
21-
#[macro_use] extern crate lazy_static_include;
21+
use lazy_static_include::*;
2222
2323
lazy_static_include_str! {
2424
/// doc
2525
TEST => "data/test.txt",
26+
}
27+
28+
lazy_static_include_str! {
2629
/// doc
2730
pub TEST2 => ("data", "test-2.txt"),
2831
}
@@ -32,11 +35,14 @@ assert_eq!("Some text...", TEST2);
3235
```
3336
3437
```rust
35-
#[macro_use] extern crate lazy_static_include;
38+
use lazy_static_include::*;
3639
3740
lazy_static_include_bytes! {
3841
/// doc
3942
TEST => "data/test.txt",
43+
}
44+
45+
lazy_static_include_bytes! {
4046
/// doc
4147
pub TEST2 => ("data", "test-2.txt"),
4248
}
@@ -48,7 +54,7 @@ assert_eq!("Some text...".as_bytes(), TEST2);
4854
You should notice that the value created from `lazy_static_include_bytes` and `lazy_static_include_str` macros isn't equal to `&'static [u8]` or `&'static str`. If you want to get an exact `&'static [u8]` or `&'static str` reference, you can **dereference** the value.
4955
5056
```rust
51-
#[macro_use] extern crate lazy_static_include;
57+
use lazy_static_include::*;
5258
5359
lazy_static_include_bytes! {
5460
/// doc
@@ -58,6 +64,8 @@ lazy_static_include_bytes! {
5864
let data: &'static [u8] = *TEST;
5965
```
6066
67+
Also, private items (without `pub`) and public items (with `pub*`) cannot be put together.
68+
6169
## Include Array
6270
6371
There is a special macro `lazy_static_include_array` which can include arrays from files.
@@ -69,11 +77,14 @@ Be careful when you distribute your program.
6977
The paths used for `lazy_static_include_array` are relative to **CARGO_MANIFEST_DIR**.
7078
7179
```rust
72-
#[macro_use] extern crate lazy_static_include;
80+
use lazy_static_include::*;
7381
7482
lazy_static_include_array! {
7583
/// doc
7684
TEST: [u64; 5] => "data/u64_array.txt",
85+
}
86+
87+
lazy_static_include_array! {
7788
/// doc
7889
pub TEST2: [&'static str; 3] => ("data", "string_array.txt")
7990
}

src/macro_include_array.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,24 +372,33 @@ macro_rules! lazy_static_include_array {
372372
( @type $name:ident: [&'static str; $s:expr], $path:expr ) => {
373373
$crate::lazy_static_include_array!(@s $name: [bool; $s], $path);
374374
};
375-
( @unit $(#[$attr: meta])* ($v:tt) $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr ) => {
375+
( @unit $(#[$attr: meta])* $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr ) => {
376376
$crate::lazy_static::lazy_static! {
377377
$(#[$attr])*
378378
static ref $name: [$(& $lt)? $t; $s] = $crate::lazy_static_include_array!(@type $name: [$(& $lt)? $t; $s], $path);
379379
}
380380
};
381-
( @unit $(#[$attr: meta])* (pub$(($($v:tt)+))?) $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr ) => {
381+
( @unit $(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr ) => {
382382
$crate::lazy_static::lazy_static! {
383383
$(#[$attr])*
384384
pub$(($($v)+))? static ref $name: [$(& $lt)? $t; $s] = $crate::lazy_static_include_array!(@type $name: [$(& $lt)? $t; $s], $path);
385385
}
386386
};
387-
( $($(#[$attr: meta])* $v:vis $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr),* $(,)* ) => {
387+
( $($(#[$attr: meta])* $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr),* $(,)* ) => {
388388
$(
389389
$crate::lazy_static_include_array! {
390390
@unit
391391
$(#[$attr])*
392-
($v) $name: [$(& $lt)? $t; $s] => $path
392+
$name: [$(& $lt)? $t; $s] => $path
393+
}
394+
)*
395+
};
396+
( $($(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr),* $(,)* ) => {
397+
$(
398+
$crate::lazy_static_include_array! {
399+
@unit
400+
$(#[$attr])*
401+
pub$(($($v)+))? $name: [$(& $lt)? $t; $s] => $path
393402
}
394403
)*
395404
};
@@ -401,24 +410,33 @@ macro_rules! lazy_static_include_array {
401410
/// The file is located relative to the directory containing the manifest of your package.
402411
#[macro_export]
403412
macro_rules! lazy_static_include_array {
404-
( @unit $(#[$attr: meta])* ($v:tt) $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr ) => {
413+
( @unit $(#[$attr: meta])* $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr ) => {
405414
$crate::lazy_static::lazy_static! {
406415
$(#[$attr])*
407416
static ref $name: [$(& $lt)? $t; $s] = include!($crate::manifest_dir_macros::path!($path));
408417
}
409418
};
410-
( @unit $(#[$attr: meta])* (pub$(($($v:tt)+))?) $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr ) => {
419+
( @unit $(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr ) => {
411420
$crate::lazy_static::lazy_static! {
412421
$(#[$attr])*
413422
pub$(($($v)+))? static ref $name: [$(& $lt)? $t; $s] = include!($crate::manifest_dir_macros::path!($path));
414423
}
415424
};
416-
( $($(#[$attr: meta])* $v:vis $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr),* $(,)* ) => {
425+
( $($(#[$attr: meta])* $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr),* $(,)* ) => {
426+
$(
427+
$crate::lazy_static_include_array! {
428+
@unit
429+
$(#[$attr])*
430+
$name: [$(& $lt)? $t; $s] => $path
431+
}
432+
)*
433+
};
434+
( $($(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr),* $(,)* ) => {
417435
$(
418436
$crate::lazy_static_include_array! {
419437
@unit
420438
$(#[$attr])*
421-
($v) $name: [$(& $lt)? $t; $s] => $path
439+
pub$(($($v)+))? $name: [$(& $lt)? $t; $s] => $path
422440
}
423441
)*
424442
};

src/macro_include_bytes.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,37 @@ macro_rules! lazy_static_include_bytes {
5555
}
5656
}
5757
};
58-
( @unit $(#[$attr: meta])* ($v:tt) $name:ident => $path:expr ) => {
58+
( @unit $(#[$attr: meta])* $name:ident => $path:expr ) => {
5959
$crate::lazy_static::lazy_static! {
6060
$(#[$attr])*
6161
static ref $name: &'static [u8] = $crate::lazy_static_include_bytes!(@inner $name, $path);
6262
}
6363

6464
$crate::lazy_static_include_bytes!(@impl $name);
6565
};
66-
( @unit $(#[$attr: meta])* (pub$(($($v:tt)+))?) $name:ident => $path:expr ) => {
66+
( @unit $(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr ) => {
6767
$crate::lazy_static::lazy_static! {
6868
$(#[$attr])*
6969
pub$(($($v)+))? static ref $name: &'static [u8] = $crate::lazy_static_include_bytes!(@inner $name, $path);
7070
}
7171

7272
$crate::lazy_static_include_bytes!(@impl $name);
7373
};
74-
( $($(#[$attr: meta])* $v:vis $name:ident => $path:expr),* $(,)* ) => {
74+
( $($(#[$attr: meta])* $name:ident => $path:expr),* $(,)* ) => {
7575
$(
7676
$crate::lazy_static_include_bytes! {
7777
@unit
7878
$(#[$attr])*
79-
($v) $name => $path
79+
$name => $path
80+
}
81+
)*
82+
};
83+
( $($(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr),* $(,)* ) => {
84+
$(
85+
$crate::lazy_static_include_bytes! {
86+
@unit
87+
$(#[$attr])*
88+
pub$(($($v)+))? $name => $path
8089
}
8190
)*
8291
};
@@ -123,28 +132,37 @@ macro_rules! lazy_static_include_bytes {
123132
}
124133
}
125134
};
126-
( @unit $(#[$attr: meta])* ($v:tt) $name:ident => $path:expr ) => {
135+
( @unit $(#[$attr: meta])* $name:ident => $path:expr ) => {
127136
$crate::lazy_static::lazy_static! {
128137
$(#[$attr])*
129138
static ref $name: &'static [u8] = include_bytes!($crate::manifest_dir_macros::path!($path));
130139
}
131140

132141
$crate::lazy_static_include_bytes!(@impl $name);
133142
};
134-
( @unit $(#[$attr: meta])* (pub$(($($v:tt)+))?) $name:ident => $path:expr ) => {
143+
( @unit $(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr ) => {
135144
$crate::lazy_static::lazy_static! {
136145
$(#[$attr])*
137146
pub$(($($v)+))? static ref $name: &'static [u8] = include_bytes!($crate::manifest_dir_macros::path!($path));
138147
}
139148

140149
$crate::lazy_static_include_bytes!(@impl $name);
141150
};
142-
( $($(#[$attr: meta])* $v:vis $name:ident => $path:expr),* $(,)* ) => {
151+
( $($(#[$attr: meta])* $name:ident => $path:expr),* $(,)* ) => {
152+
$(
153+
$crate::lazy_static_include_bytes! {
154+
@unit
155+
$(#[$attr])*
156+
$name => $path
157+
}
158+
)*
159+
};
160+
( $($(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr),* $(,)* ) => {
143161
$(
144162
$crate::lazy_static_include_bytes! {
145163
@unit
146164
$(#[$attr])*
147-
($v) $name => $path
165+
pub$(($($v)+))? $name => $path
148166
}
149167
)*
150168
};

src/macro_include_str.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,37 @@ macro_rules! lazy_static_include_str {
7474
}
7575
}
7676
};
77-
( @unit $(#[$attr: meta])* ($v:tt) $name:ident => $path:expr ) => {
77+
( @unit $(#[$attr: meta])* $name:ident => $path:expr ) => {
7878
$crate::lazy_static::lazy_static! {
7979
$(#[$attr])*
8080
static ref $name: &'static str = $crate::lazy_static_include_str!(@inner $name, $path);
8181
}
8282

8383
$crate::lazy_static_include_str!(@impl $name);
8484
};
85-
( @unit $(#[$attr: meta])* (pub$(($($v:tt)+))?) $name:ident => $path:expr ) => {
85+
( @unit $(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr ) => {
8686
$crate::lazy_static::lazy_static! {
8787
$(#[$attr])*
8888
pub$(($($v)+))? static ref $name: &'static str = $crate::lazy_static_include_str!(@inner $name, $path);
8989
}
9090

9191
$crate::lazy_static_include_str!(@impl $name);
9292
};
93-
( $($(#[$attr: meta])* $v:vis $name:ident => $path:expr),* $(,)* ) => {
93+
( $($(#[$attr: meta])* $name:ident => $path:expr),* $(,)* ) => {
9494
$(
9595
$crate::lazy_static_include_str! {
9696
@unit
9797
$(#[$attr])*
98-
($v) $name => $path
98+
$name => $path
99+
}
100+
)*
101+
};
102+
( $($(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr),* $(,)* ) => {
103+
$(
104+
$crate::lazy_static_include_str! {
105+
@unit
106+
$(#[$attr])*
107+
pub$(($($v)+))? $name => $path
99108
}
100109
)*
101110
};
@@ -161,28 +170,45 @@ macro_rules! lazy_static_include_str {
161170
}
162171
}
163172
};
164-
( @unit $(#[$attr: meta])* ($v:tt) $name:ident => $path:expr ) => {
173+
( @unit $(#[$attr: meta])* $name:ident => $path:expr ) => {
165174
$crate::lazy_static::lazy_static! {
166175
$(#[$attr])*
167176
static ref $name: &'static str = include_str!($crate::manifest_dir_macros::path!($path));
168177
}
169178

170179
$crate::lazy_static_include_str!(@impl $name);
171180
};
172-
( @unit $(#[$attr: meta])* (pub$(($($v:tt)+))?) $name:ident => $path:expr ) => {
181+
( @unit $(#[$attr: meta])* pub $name:ident => $path:expr ) => {
182+
$crate::lazy_static::lazy_static! {
183+
$(#[$attr])*
184+
pub static ref $name: &'static str = include_str!($crate::manifest_dir_macros::path!($path));
185+
}
186+
187+
$crate::lazy_static_include_str!(@impl $name);
188+
};
189+
( @unit $(#[$attr: meta])* pub($($vis:tt)+) $name:ident => $path:expr ) => {
173190
$crate::lazy_static::lazy_static! {
174191
$(#[$attr])*
175-
pub$(($($v)+))? static ref $name: &'static str = include_str!($crate::manifest_dir_macros::path!($path));
192+
pub($($vis)+) static ref $name: &'static str = include_str!($crate::manifest_dir_macros::path!($path));
176193
}
177194

178195
$crate::lazy_static_include_str!(@impl $name);
179196
};
180-
( $($(#[$attr: meta])* $v:vis $name:ident => $path:expr),* $(,)* ) => {
197+
( $($(#[$attr: meta])* $name:ident => $path:expr),* $(,)* ) => {
198+
$(
199+
$crate::lazy_static_include_str! {
200+
@unit
201+
$(#[$attr])*
202+
$name => $path
203+
}
204+
)*
205+
};
206+
( $($(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr),* $(,)* ) => {
181207
$(
182208
$crate::lazy_static_include_str! {
183209
@unit
184210
$(#[$attr])*
185-
($v) $name => $path
211+
pub$(($($v)+))? $name => $path
186212
}
187213
)*
188214
};

0 commit comments

Comments
 (0)