Skip to content

Commit 1dca3d0

Browse files
authored
Ensure tests requiring std feature are conditionally compiled (#9)
Ensure that any test or example that requires std in order to compile and run are conditionally compiled behind the `std` crate feature. Addresses #8.
1 parent 52987d6 commit 1dca3d0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pub use lifetime_free::LifetimeFree;
127127
/// Specialization in a blanket trait implementation:
128128
///
129129
/// ```
130+
/// # #[cfg(feature = "std")] {
130131
/// use std::fmt::Display;
131132
/// use castaway::cast;
132133
///
@@ -160,6 +161,7 @@ pub use lifetime_free::LifetimeFree;
160161
///
161162
/// println!("specialized: {}", String::from("hello").fast_to_string());
162163
/// println!("default: {}", "hello".fast_to_string());
164+
/// # }
163165
/// ```
164166
#[macro_export]
165167
macro_rules! cast {
@@ -311,6 +313,7 @@ mod tests {
311313

312314
inner2(&slice);
313315

316+
#[allow(clippy::needless_lifetimes)]
314317
fn inner3<'a>(value: &'a mut [u8]) {
315318
assert_eq!(cast!(value, &mut [u8]), Ok(&mut [1, 1][..]));
316319
}
@@ -341,6 +344,7 @@ mod tests {
341344
() => {};
342345

343346
(
347+
$(#[$meta:meta])*
344348
for $TARGET:ty as $name:ident {
345349
$(
346350
$value:expr => $matches:pat $(if $guard:expr)?,
@@ -349,6 +353,7 @@ mod tests {
349353
$($tail:tt)*
350354
) => {
351355
paste::paste! {
356+
$(#[$meta])*
352357
#[test]
353358
#[allow(non_snake_case)]
354359
fn [<cast_lifetime_free_ $name>]() {
@@ -364,6 +369,7 @@ mod tests {
364369
)*
365370
}
366371

372+
$(#[$meta])*
367373
#[test]
368374
#[allow(non_snake_case)]
369375
fn [<cast_lifetime_free_ref_ $name>]() {
@@ -379,6 +385,7 @@ mod tests {
379385
)*
380386
}
381387

388+
$(#[$meta])*
382389
#[test]
383390
#[allow(non_snake_case)]
384391
fn [<cast_lifetime_free_mut_ $name>]() {
@@ -401,6 +408,7 @@ mod tests {
401408
};
402409

403410
(
411+
$(#[$meta:meta])*
404412
for $TARGET:ty {
405413
$(
406414
$value:expr => $matches:pat $(if $guard:expr)?,
@@ -409,6 +417,7 @@ mod tests {
409417
$($tail:tt)*
410418
) => {
411419
paste::paste! {
420+
$(#[$meta])*
412421
#[test]
413422
#[allow(non_snake_case)]
414423
fn [<cast_lifetime_free_ $TARGET>]() {
@@ -424,6 +433,7 @@ mod tests {
424433
)*
425434
}
426435

436+
$(#[$meta])*
427437
#[test]
428438
#[allow(non_snake_case)]
429439
fn [<cast_lifetime_free_ref_ $TARGET>]() {
@@ -439,6 +449,7 @@ mod tests {
439449
)*
440450
}
441451

452+
$(#[$meta])*
442453
#[test]
443454
#[allow(non_snake_case)]
444455
fn [<cast_lifetime_free_mut_ $TARGET>]() {
@@ -478,6 +489,7 @@ mod tests {
478489
3.2f64 => Err(v) if v == 3.2f64,
479490
}
480491

492+
#[cfg(feature = "std")]
481493
for String {
482494
String::from("hello world") => Ok(ref v) if v.as_str() == "hello world",
483495
"hello world" => Err("hello world"),

0 commit comments

Comments
 (0)