From 6b4cf5b7d8043469c9856f6578d282f9532d7fe0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 13 Jul 2020 15:54:12 +0200 Subject: Move stdx macros into submodule --- crates/stdx/src/lib.rs | 21 ++------------------- crates/stdx/src/macros.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 crates/stdx/src/macros.rs (limited to 'crates/stdx') diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 3b605c79d..988853ed2 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -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>; diff --git a/crates/stdx/src/macros.rs b/crates/stdx/src/macros.rs new file mode 100644 index 000000000..0f7690a67 --- /dev/null +++ b/crates/stdx/src/macros.rs @@ -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)*); } + }; +} -- cgit v1.2.3