pub mod collections;
pub use collections::*;
pub mod math;
pub use math::*;
pub mod eyre;
pub use eyre::*;
pub mod format;
pub use format::*;
pub mod info_size;
pub use info_size::*;
pub mod serde;
pub use serde::*;
#[macro_export]
macro_rules! log {
($($arg:tt)*) => {{
println!($($arg)*);
tracing::info!($($arg)*);
}};
}
#[macro_export]
macro_rules! print_rolling {
($($arg:tt)*) => {{
eprint!("\r\x1B[2K{}", format_args!($($arg)*));
}};
}
#[macro_export]
macro_rules! elog {
($($arg:tt)*) => {{
eprintln!($($arg)*);
tracing::debug!($($arg)*);
}};
}
#[cfg(feature = "tracing")]
pub mod tracing;
#[cfg(feature = "tracing")]
pub use tracing::*;
#[cfg(all(feature = "tracing", feature = "xdg"))]
#[macro_export]
macro_rules! clientside {
() => {
v_utils::clientside!(None::<String>);
};
($fname:expr) => {
color_eyre::install().unwrap();
miette::set_hook(Box::new(|_| Box::new(miette::MietteHandlerOpts::new().terminal_links(true).build()))).expect("miette hook already set");
if std::env::var("__IS_INTEGRATION_TEST").is_ok() {
unsafe { std::env::set_var("LOG_DIRECTIVES", concat!("debug,", env!("CARGO_PKG_NAME"), "=debug")) };
v_utils::utils::init_subscriber(v_utils::utils::LogDestination::default());
} else {
let mut dest = v_utils::utils::LogDestination::xdg(env!("CARGO_PKG_NAME"))
.stderr_errors(true)
.compiled_directives(option_env!("LOG_DIRECTIVES"));
if let Some(fname) = $fname {
dest = dest.fname(fname);
}
v_utils::utils::init_subscriber(dest);
}
};
}
#[cfg(all(feature = "tracing", not(feature = "xdg")))]
#[macro_export]
macro_rules! clientside {
() => {
v_utils::clientside!(None::<String>);
};
($fname:expr) => {
let _ = $fname; eprintln!("[v_utils] Warning: `xdg` feature not enabled, logging to stdout instead of file. Add `xdg` feature to v_utils dependency to enable file logging.");
color_eyre::install().unwrap();
miette::set_hook(Box::new(|_| Box::new(miette::MietteHandlerOpts::new().terminal_links(true).context_lines(3).build()))).expect("miette hook already set");
v_utils::utils::init_subscriber(v_utils::utils::LogDestination::default().compiled_directives(option_env!("LOG_DIRECTIVES")));
};
}
#[macro_export]
macro_rules! define_str_enum {
($(#[$meta:meta])* $vis:vis enum $name:ident {
$($(#[$variant_meta:meta])* $variant:ident => $str:expr),* $(,)?
}) => {
$(#[$meta])*
$vis enum $name {
$($(#[$variant_meta])* $variant),*
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
$(Self::$variant => write!(f, "{}", $str)),*
}
}
}
impl std::str::FromStr for $name {
type Err = eyre::Report;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
$($str => Ok(Self::$variant)),*,
_ => eyre::bail!("Invalid {} string: {}", stringify!($name).to_lowercase(), s),
}
}
}
};
}