mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Move stdx macros into submodule
This commit is contained in:
parent
4b1c372436
commit
6b4cf5b7d8
@ -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
19
crates/stdx/src/macros.rs
Normal 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)*); }
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user