Move stdx macros into submodule

This commit is contained in:
Aleksey Kladov 2020-07-13 15:54:12 +02:00
parent 4b1c372436
commit 6b4cf5b7d8
2 changed files with 21 additions and 19 deletions

View File

@ -1,30 +1,13 @@
//! Missing batteries for standard libraries.
use std::{cell::Cell, fmt, time::Instant};
mod macros;
#[inline(always)]
pub fn is_ci() -> bool {
option_env!("CI").is_some()
}
#[macro_export]
macro_rules! eprintln {
($($tt:tt)*) => {{
if $crate::is_ci() {
panic!("Forgot to remove debug-print?")
}
std::eprintln!($($tt)*)
}}
}
/// Appends formatted string to a `String`.
#[macro_export]
macro_rules! format_to {
($buf:expr) => ();
($buf:expr, $lit:literal $($arg:tt)*) => {
{ use ::std::fmt::Write as _; let _ = ::std::write!($buf, $lit $($arg)*); }
};
}
pub trait SepBy: Sized {
/// Returns an `impl fmt::Display`, which joins elements via a separator.
fn sep_by<'a>(self, sep: &'a str) -> SepByBuilder<'a, Self>;

19
crates/stdx/src/macros.rs Normal file
View File

@ -0,0 +1,19 @@
//! Convenience macros.
#[macro_export]
macro_rules! eprintln {
($($tt:tt)*) => {{
if $crate::is_ci() {
panic!("Forgot to remove debug-print?")
}
std::eprintln!($($tt)*)
}}
}
/// Appends formatted string to a `String`.
#[macro_export]
macro_rules! format_to {
($buf:expr) => ();
($buf:expr, $lit:literal $($arg:tt)*) => {
{ use ::std::fmt::Write as _; let _ = ::std::write!($buf, $lit $($arg)*); }
};
}