Skip to content

Commit

Permalink
refactor: use cfg_if crate for better cfg checks (#9)
Browse files Browse the repository at this point in the history
VSCode shows one side of the cfg as unused all the time, annoyingly
  • Loading branch information
joshka committed Feb 7, 2024
1 parent fdb1702 commit 2831143
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
reorder_imports = true
use_field_init_shorthand = true
use_try_shorthand = true
wrap_comments = true
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ build = "build.rs"
# simplifications in the code.

better-panic = "0.3.0"
cfg-if = "1.0.0"
chrono = "0.4.31"
clap = { version = "4.4.11", features = ["derive", "cargo", "wrap_help", "unicode", "string", "unstable-styles", "color"] }
color-eyre = "0.6.2"
Expand Down
13 changes: 8 additions & 5 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use color_eyre::{
use tracing::error;

use crate::tui;
use cfg_if::cfg_if;

pub fn install_hooks() -> Result<()> {
let (panic_hook, eyre_hook) = HookBuilder::default()
Expand All @@ -19,11 +20,13 @@ pub fn install_hooks() -> Result<()> {
.display_env_section(false)
.into_hooks();

#[cfg(debug_assertions)]
install_better_panic();
#[cfg(not(debug_assertions))]
install_human_panic();

cfg_if! {
if #[cfg(debug_assertions)] {
install_better_panic();
} else {
install_human_panic();
}
}
install_color_eyre_panic_hook(panic_hook);
install_eyre_hook(eyre_hook)?;

Expand Down

0 comments on commit 2831143

Please sign in to comment.