| 1 |
#![cfg_attr(not(feature = "std"), no_std)] |
| 2 |
|
| 3 |
mod core { |
| 4 |
#[cfg(not(feature = "std"))] |
| 5 |
pub use core::*; |
| 6 |
#[cfg(feature = "std")] |
| 7 |
pub use std::*; |
| 8 |
} |
| 9 |
pub use self::core::cmp::PartialEq; |
| 10 |
pub use self::core::prelude::*; |
| 11 |
pub use self::core::{cfg, fmt, fmt::Debug, matches}; |
| 12 |
|
| 13 |
pub enum BuildModel { |
| 14 |
Debug, |
| 15 |
Release, |
| 16 |
} |
| 17 |
|
| 18 |
pub const fn build_channel() -> BuildModel { |
| 19 |
if cfg!(debug_assertions) { |
| 20 |
return BuildModel::Debug; |
| 21 |
} |
| 22 |
BuildModel::Release |
| 23 |
} |
| 24 |
|
| 25 |
impl fmt::Display for BuildModel { |
| 26 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 27 |
match self { |
| 28 |
Self::Debug => f.write_str("debug"), |
| 29 |
Self::Release => f.write_str("release"), |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
pub const fn is_debug() -> bool { |
| 34 |
matches!(build_channel(), BuildModel::Debug) |
| 35 |
} |
| 36 |
|
| 37 |
pub const fn is_release() -> bool { |
| 38 |
matches!(build_channel(), BuildModel::Release) |
| 39 |
} |
| 40 |
|
| •41 |
/* |
| 42 |
#[cfg(test)] |
| 43 |
mod tests { |
| 44 |
use xshell::{cmd, Shell}; |
| 45 |
|
| 46 |
#[test] |
| 47 |
fn test_std() { |
| 48 |
let sh = Shell::new().unwrap(); |
| 49 |
let repo = "is_debug_test"; |
| 50 |
let _ = cmd!(sh, "rm -rf {repo}").run(); |
| 51 |
cmd!(sh, "cargo new {repo}").run().unwrap(); |
| 52 |
sh.change_dir(repo); |
| 53 |
let cargo_content = r#" |
| 54 |
[package] |
| 55 |
name = "is_debug_test" |
| 56 |
version = "0.1.0" |
| 57 |
edition = "2021" |
| 58 |
|
| 59 |
[dependencies] |
| 60 |
is_debug = {path = "../"} |
| 61 |
"#; |
| 62 |
|
| 63 |
sh.write_file("Cargo.toml", cargo_content).unwrap(); |
| 64 |
|
| 65 |
let main_debug = r#" |
| 66 |
fn main() { |
| 67 |
assert!(is_debug::is_debug()) |
| 68 |
} |
| 69 |
"#; |
| 70 |
|
| 71 |
let main_release = r#" |
| 72 |
fn main() { |
| 73 |
assert!(is_debug::is_release()) |
| 74 |
} |
| 75 |
"#; |
| 76 |
sh.write_file("src/main.rs", main_debug).unwrap(); |
| 77 |
cmd!(sh, "cargo run").run().unwrap(); |
| 78 |
sh.write_file("src/main.rs", main_release).unwrap(); |
| 79 |
cmd!(sh, "cargo run --release").run().unwrap(); |
| 80 |
|
| 81 |
cmd!(sh, "rm -rf ../{repo}").run().unwrap(); |
| 82 |
} |
| 83 |
} |
| •84 |
*/ |