Skip to main content

gchemol_gut/
lib.rs

1// [[file:../gut.note::36e53031][36e53031]]
2#![deny(clippy::all)]
3
4#[cfg(not(target_arch = "wasm32"))]
5pub mod cli;
6#[cfg(not(target_arch = "wasm32"))]
7pub mod fs;
8
9pub mod config;
10pub mod logger;
11pub mod utils;
12// 36e53031 ends here
13
14// [[file:../gut.note::b07726f0][b07726f0]]
15pub mod prelude {
16    pub use crate::config::Configure;
17
18    pub use itertools::Itertools;
19
20    pub use anyhow::Context as _Context; // avoid name conflicting
21    pub use anyhow::Ok as Ok_; // useful when return a Result in a closure
22    pub use anyhow::{anyhow, bail, ensure, format_err};
23    pub use anyhow::{Error, Result};
24
25    #[doc(hidden)]
26    // NOTE: to make serde deriving work, serde must be included in Cargo.toml
27    pub use serde::*;
28
29    pub use super::log_dbg;
30    #[doc(hidden)]
31    pub use log::{debug, error, info, trace, warn};
32
33    pub use rayon::prelude::*;
34
35    // for write! and writeln! macros
36    // avoid name conflict with std::io::Write
37    pub use std::fmt::Write as FmtWrite;
38    pub use std::io::{Read, Write};
39
40    // FooBar::from_str
41    pub use std::str::FromStr;
42
43    // provides shell_escape_lossy method for `Path`
44    #[cfg(not(target_arch = "wasm32"))]
45    pub use crate::fs::{ShellEscapeExt, ShellEscapeLossyExt};
46}
47
48// re-exports external crates
49pub use itertools;
50pub use rayon;
51
52/// Similar to std::dbg! macro, but print with info! instead of eprintln!
53#[macro_export]
54macro_rules! log_dbg {
55    () => {
56        info!("{}:{}", file!(), line!())
57    };
58    ($val:expr $(,)?) => {
59        // Use of `match` here is intentional because it affects the lifetimes
60        // of temporaries - https://stackoverflow.com/a/48732525/1063961
61        match $val {
62            tmp => {
63                info!("{}:{} {} = {:#?}",
64                      file!(), line!(), stringify!($val), &tmp);
65                tmp
66            }
67        }
68    };
69    ($($val:expr),+ $(,)?) => {
70        ($($crate::log_dbg!($val)),+,)
71    };
72}
73// b07726f0 ends here