Skip to content

Commit a901ea1

Browse files
committed
use the manifest-dir-macros crate to check the existence of paths during compilation
1 parent ca23412 commit a901ea1

File tree

6 files changed

+38
-41
lines changed

6 files changed

+38
-41
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lazy-static-include"
3-
version = "3.0.7"
3+
version = "3.1.0"
44
authors = ["Magic Len <len@magiclen.org>"]
55
edition = "2018"
66
repository = "https://github.com/magiclen/lazy-static-include"
@@ -14,7 +14,7 @@ include = ["src/**/*", "Cargo.toml", "README.md", "LICENSE", "benches/bench.rs"]
1414

1515
[dependencies]
1616
lazy_static = "1.4"
17-
slash-formatter = "3.1"
17+
manifest-dir-macros = "0.1"
1818
syn = { version = "1", features = ["full"] }
1919

2020
[dev-dependencies]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ cargo bench
118118
pub extern crate lazy_static;
119119

120120
#[doc(hidden)]
121-
pub extern crate slash_formatter;
121+
pub extern crate manifest_dir_macros;
122122

123123
#[doc(hidden)]
124124
pub extern crate syn;

src/macro_include_array.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
macro_rules! lazy_static_include_array {
77
( @i $name:ident: [$t:ident; $s:expr], $path:expr ) => {
88
{
9-
let path = $crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path);
9+
let path = $crate::manifest_dir_macros::not_directory_path!($path);
1010

1111
let text = ::std::fs::read_to_string(path).unwrap();
1212

@@ -71,7 +71,7 @@ macro_rules! lazy_static_include_array {
7171
};
7272
( @u $name:ident: [$t:ident; $s:expr], $path:expr ) => {
7373
{
74-
let path = $crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path);
74+
let path = $crate::manifest_dir_macros::not_directory_path!($path);
7575

7676
let text = ::std::fs::read_to_string(path).unwrap();
7777

@@ -120,7 +120,7 @@ macro_rules! lazy_static_include_array {
120120
};
121121
( @f $name:ident: [$t:ident; $s:expr], $path:expr ) => {
122122
{
123-
let path = $crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path);
123+
let path = $crate::manifest_dir_macros::not_directory_path!($path);
124124

125125
let text = ::std::fs::read_to_string(path).unwrap();
126126

@@ -200,7 +200,7 @@ macro_rules! lazy_static_include_array {
200200
};
201201
( @c $name:ident: [$t:ident; $s:expr], $path:expr ) => {
202202
{
203-
let path = $crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path);
203+
let path = $crate::manifest_dir_macros::not_directory_path!($path);
204204

205205
let text = ::std::fs::read_to_string(path).unwrap();
206206

@@ -236,7 +236,7 @@ macro_rules! lazy_static_include_array {
236236
};
237237
( @b $name:ident: [$t:ident; $s:expr], $path:expr ) => {
238238
{
239-
let path = $crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path);
239+
let path = $crate::manifest_dir_macros::not_directory_path!($path);
240240

241241
let text = ::std::fs::read_to_string(path).unwrap();
242242

@@ -274,7 +274,7 @@ macro_rules! lazy_static_include_array {
274274
{
275275
use ::std::mem::{forget, transmute};
276276

277-
let path = $crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path);
277+
let path = $crate::manifest_dir_macros::not_directory_path!($path);
278278

279279
let text = ::std::fs::read_to_string(path).unwrap();
280280

@@ -404,13 +404,13 @@ macro_rules! lazy_static_include_array {
404404
( @unit $(#[$attr: meta])* ($v:tt) $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr ) => {
405405
$crate::lazy_static::lazy_static! {
406406
$(#[$attr])*
407-
static ref $name: [$(& $lt)? $t; $s] = include!($crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path));
407+
static ref $name: [$(& $lt)? $t; $s] = include!($crate::manifest_dir_macros::path!($path));
408408
}
409409
};
410410
( @unit $(#[$attr: meta])* (pub$(($($v:tt)+))?) $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr ) => {
411411
$crate::lazy_static::lazy_static! {
412412
$(#[$attr])*
413-
pub$(($($v)+))? static ref $name: [$(& $lt)? $t; $s] = include!($crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path));
413+
pub$(($($v)+))? static ref $name: [$(& $lt)? $t; $s] = include!($crate::manifest_dir_macros::path!($path));
414414
}
415415
};
416416
( $($(#[$attr: meta])* $v:vis $name:ident: [$(& $lt:lifetime)? $t:ident; $s:expr] => $path:expr),* $(,)* ) => {

src/macro_include_bytes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! lazy_static_include_bytes {
4444
use ::std::fs;
4545
use ::std::mem::{forget, transmute};
4646

47-
let path = $crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path);
47+
let path = $crate::manifest_dir_macros::not_directory_path!($path);
4848

4949
let data = fs::read(path).unwrap();
5050

@@ -126,15 +126,15 @@ macro_rules! lazy_static_include_bytes {
126126
( @unit $(#[$attr: meta])* ($v:tt) $name:ident => $path:expr ) => {
127127
$crate::lazy_static::lazy_static! {
128128
$(#[$attr])*
129-
static ref $name: &'static [u8] = include_bytes!($crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path));
129+
static ref $name: &'static [u8] = include_bytes!($crate::manifest_dir_macros::path!($path));
130130
}
131131

132132
$crate::lazy_static_include_bytes!(@impl $name);
133133
};
134134
( @unit $(#[$attr: meta])* (pub$(($($v:tt)+))?) $name:ident => $path:expr ) => {
135135
$crate::lazy_static::lazy_static! {
136136
$(#[$attr])*
137-
pub$(($($v)+))? static ref $name: &'static [u8] = include_bytes!($crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path));
137+
pub$(($($v)+))? static ref $name: &'static [u8] = include_bytes!($crate::manifest_dir_macros::path!($path));
138138
}
139139

140140
$crate::lazy_static_include_bytes!(@impl $name);

src/macro_include_str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ macro_rules! lazy_static_include_str {
6363
use ::std::fs;
6464
use ::std::mem::{forget, transmute};
6565

66-
let path = $crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path);
66+
let path = $crate::manifest_dir_macros::not_directory_path!($path);
6767

6868
let text = fs::read_to_string(path).unwrap();
6969

@@ -164,15 +164,15 @@ macro_rules! lazy_static_include_str {
164164
( @unit $(#[$attr: meta])* ($v:tt) $name:ident => $path:expr ) => {
165165
$crate::lazy_static::lazy_static! {
166166
$(#[$attr])*
167-
static ref $name: &'static str = include_str!($crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path));
167+
static ref $name: &'static str = include_str!($crate::manifest_dir_macros::path!($path));
168168
}
169169

170170
$crate::lazy_static_include_str!(@impl $name);
171171
};
172172
( @unit $(#[$attr: meta])* (pub$(($($v:tt)+))?) $name:ident => $path:expr ) => {
173173
$crate::lazy_static::lazy_static! {
174174
$(#[$attr])*
175-
pub$(($($v)+))? static ref $name: &'static str = include_str!($crate::slash_formatter::concat_with_file_separator_debug_release!(env!("CARGO_MANIFEST_DIR"), $path));
175+
pub$(($($v)+))? static ref $name: &'static str = include_str!($crate::manifest_dir_macros::path!($path));
176176
}
177177

178178
$crate::lazy_static_include_str!(@impl $name);

tests/macros.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#[macro_use]
22
extern crate lazy_static_include;
33

4-
#[macro_use]
5-
extern crate slash_formatter;
6-
74
#[macro_use]
85
extern crate assert_approx_eq;
96

107
#[test]
118
fn include_str() {
129
lazy_static_include_str! {
13-
TEST => concat_with_file_separator!("data", "test.txt"),
14-
pub TEST2 => concat_with_file_separator!("data", "test-2.txt"),
10+
TEST => "data/test.txt",
11+
pub TEST2 => "data/test-2.txt",
1512
}
1613

1714
let _data: &'static str = *TEST;
@@ -23,8 +20,8 @@ fn include_str() {
2320
#[test]
2421
fn include_bytes() {
2522
lazy_static_include_bytes! {
26-
TEST => concat_with_file_separator!("data", "test.txt"),
27-
pub TEST2 => concat_with_file_separator!("data", "test-2.txt"),
23+
TEST => "data/test.txt",
24+
pub TEST2 => "data/test-2.txt",
2825
}
2926

3027
let _data: &'static [u8] = *TEST;
@@ -36,7 +33,7 @@ fn include_bytes() {
3633
#[test]
3734
fn include_array_isize() {
3835
lazy_static_include_array! {
39-
TEST: [isize; 5] => concat_with_file_separator!("data", "isize_array.txt"),
36+
TEST: [isize; 5] => "data/isize_array.txt",
4037
}
4138

4239
assert_eq!(123, TEST[0]);
@@ -49,7 +46,7 @@ fn include_array_isize() {
4946
#[test]
5047
fn include_array_i8() {
5148
lazy_static_include_array! {
52-
TEST: [i8; 5] => concat_with_file_separator!("data", "i8_array.txt"),
49+
TEST: [i8; 5] => "data/i8_array.txt",
5350
}
5451

5552
assert_eq!(12, TEST[0]);
@@ -62,7 +59,7 @@ fn include_array_i8() {
6259
#[test]
6360
fn include_array_i16() {
6461
lazy_static_include_array! {
65-
TEST: [i16; 5] => concat_with_file_separator!("data", "i16_array.txt"),
62+
TEST: [i16; 5] => "data/i16_array.txt",
6663
}
6764

6865
assert_eq!(123, TEST[0]);
@@ -75,7 +72,7 @@ fn include_array_i16() {
7572
#[test]
7673
fn include_array_i32() {
7774
lazy_static_include_array! {
78-
TEST: [i32; 5] => concat_with_file_separator!("data", "i32_array.txt"),
75+
TEST: [i32; 5] => "data/i32_array.txt",
7976
}
8077

8178
assert_eq!(123, TEST[0]);
@@ -88,7 +85,7 @@ fn include_array_i32() {
8885
#[test]
8986
fn include_array_i64() {
9087
lazy_static_include_array! {
91-
pub TEST: [i64; 5] => concat_with_file_separator!("data", "i64_array.txt"),
88+
pub TEST: [i64; 5] => "data/i64_array.txt",
9289
}
9390

9491
assert_eq!(123, TEST[0]);
@@ -101,7 +98,7 @@ fn include_array_i64() {
10198
#[test]
10299
fn include_array_i128() {
103100
lazy_static_include_array! {
104-
pub TEST: [i128; 5] => concat_with_file_separator!("data", "i128_array.txt"),
101+
pub TEST: [i128; 5] => "data/i128_array.txt",
105102
}
106103

107104
assert_eq!(123, TEST[0]);
@@ -114,7 +111,7 @@ fn include_array_i128() {
114111
#[test]
115112
fn include_array_usize() {
116113
lazy_static_include_array! {
117-
pub TEST: [usize; 5] => concat_with_file_separator!("data", "usize_array.txt"),
114+
pub TEST: [usize; 5] => "data/usize_array.txt",
118115
}
119116

120117
assert_eq!(123, TEST[0]);
@@ -127,7 +124,7 @@ fn include_array_usize() {
127124
#[test]
128125
fn include_array_u8() {
129126
lazy_static_include_array! {
130-
pub TEST: [u8; 5] => concat_with_file_separator!("data", "u8_array.txt"),
127+
pub TEST: [u8; 5] => "data/u8_array.txt",
131128
}
132129

133130
assert_eq!(12, TEST[0]);
@@ -140,7 +137,7 @@ fn include_array_u8() {
140137
#[test]
141138
fn include_array_u16() {
142139
lazy_static_include_array! {
143-
TEST: [u16; 5] => concat_with_file_separator!("data", "u16_array.txt"),
140+
TEST: [u16; 5] => "data/u16_array.txt",
144141
}
145142

146143
assert_eq!(123, TEST[0]);
@@ -153,7 +150,7 @@ fn include_array_u16() {
153150
#[test]
154151
fn include_array_u32() {
155152
lazy_static_include_array! {
156-
pub TEST: [u32; 5] => concat_with_file_separator!("data", "u32_array.txt"),
153+
pub TEST: [u32; 5] => "data/u32_array.txt",
157154
}
158155

159156
assert_eq!(123, TEST[0]);
@@ -166,7 +163,7 @@ fn include_array_u32() {
166163
#[test]
167164
fn include_array_u64() {
168165
lazy_static_include_array! {
169-
TEST: [u64; 5] => concat_with_file_separator!("data", "u64_array.txt"),
166+
TEST: [u64; 5] => "data/u64_array.txt",
170167
}
171168

172169
assert_eq!(123, TEST[0]);
@@ -179,7 +176,7 @@ fn include_array_u64() {
179176
#[test]
180177
fn include_array_u128() {
181178
lazy_static_include_array! {
182-
pub TEST: [u128; 5] => concat_with_file_separator!("data", "u128_array.txt"),
179+
pub TEST: [u128; 5] => "data/u128_array.txt",
183180
}
184181

185182
assert_eq!(123, TEST[0]);
@@ -192,7 +189,7 @@ fn include_array_u128() {
192189
#[test]
193190
fn include_array_f32() {
194191
lazy_static_include_array! {
195-
pub TEST: [f32; 5] => concat_with_file_separator!("data", "f32_array.txt"),
192+
pub TEST: [f32; 5] => "data/f32_array.txt",
196193
}
197194

198195
assert_approx_eq!(123f32, TEST[0]);
@@ -205,7 +202,7 @@ fn include_array_f32() {
205202
#[test]
206203
fn include_array_f64() {
207204
lazy_static_include_array! {
208-
pub TEST: [f64; 5] => concat_with_file_separator!("data", "f64_array.txt"),
205+
pub TEST: [f64; 5] => "data/f64_array.txt",
209206
}
210207

211208
assert_approx_eq!(123f64, TEST[0]);
@@ -218,7 +215,7 @@ fn include_array_f64() {
218215
#[test]
219216
fn include_array_char() {
220217
lazy_static_include_array! {
221-
pub TEST: [char; 3] => concat_with_file_separator!("data", "char_array.txt"),
218+
pub TEST: [char; 3] => "data/char_array.txt",
222219
}
223220

224221
assert_eq!('a', TEST[0]);
@@ -229,7 +226,7 @@ fn include_array_char() {
229226
#[test]
230227
fn include_array_bool() {
231228
lazy_static_include_array! {
232-
pub TEST: [bool; 3] => concat_with_file_separator!("data", "bool_array.txt"),
229+
pub TEST: [bool; 3] => "data/bool_array.txt",
233230
}
234231

235232
assert_eq!(false, TEST[0]);
@@ -240,7 +237,7 @@ fn include_array_bool() {
240237
#[test]
241238
fn include_array_string() {
242239
lazy_static_include_array! {
243-
pub TEST: [&'static str; 3] => concat_with_file_separator!("data", "string_array.txt"),
240+
pub TEST: [&'static str; 3] => "data/string_array.txt",
244241
}
245242

246243
assert_eq!("Hi", TEST[0]);

0 commit comments

Comments
 (0)