pub fn error(args: std::fmt::Arguments) {
eprintln!("error: {args}");
}
pub fn debug(args: std::fmt::Arguments) {
eprintln!("debug: {args}");
}
#[inline]
pub fn string(value: &'static str) -> String {
value.to_string()
}
#[macro_export]
macro_rules! string {
( $value:expr ) => {
$crate::macros::string($value)
};
}
#[macro_export]
macro_rules! debug {
( $fmt:expr $(, $args:expr )* ) => (
$crate::macros::debug(format_args!($fmt, $( $args ),*))
);
}
#[macro_export]
macro_rules! error {
( $fmt:expr $(, $args:expr )* ) => {
$crate::macros::error(format_args!($fmt, $( $args ),*));
std::process::exit(1);
}
}
#[macro_export]
macro_rules! impl_display_fmt {
($struct_name:ident, $format:expr) => {
impl std::fmt::Display for $struct_name {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
return write!(formatter, $format, self);
}
}
};
}
#[macro_export]
macro_rules! impl_display {
($x:ident) => {
impl_display_fmt!($x, "{:#?}");
};
}
#[macro_export]
macro_rules! impl_display_brief {
($x:ident) => {
impl_display_fmt!($x, "{:?}");
};
}