diff options
Diffstat (limited to 'crates/stdx/src/lib.rs')
-rw-r--r-- | crates/stdx/src/lib.rs | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 08ac6f70f..988853ed2 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs | |||
@@ -1,30 +1,13 @@ | |||
1 | //! Missing batteries for standard libraries. | 1 | //! Missing batteries for standard libraries. |
2 | use std::{cell::Cell, fmt, time::Instant}; | 2 | use std::{cell::Cell, fmt, time::Instant}; |
3 | 3 | ||
4 | mod macros; | ||
5 | |||
4 | #[inline(always)] | 6 | #[inline(always)] |
5 | pub fn is_ci() -> bool { | 7 | pub fn is_ci() -> bool { |
6 | option_env!("CI").is_some() | 8 | option_env!("CI").is_some() |
7 | } | 9 | } |
8 | 10 | ||
9 | #[macro_export] | ||
10 | macro_rules! eprintln { | ||
11 | ($($tt:tt)*) => {{ | ||
12 | if $crate::is_ci() { | ||
13 | panic!("Forgot to remove debug-print?") | ||
14 | } | ||
15 | std::eprintln!($($tt)*) | ||
16 | }} | ||
17 | } | ||
18 | |||
19 | /// Appends formatted string to a `String`. | ||
20 | #[macro_export] | ||
21 | macro_rules! format_to { | ||
22 | ($buf:expr) => (); | ||
23 | ($buf:expr, $lit:literal $($arg:tt)*) => { | ||
24 | { use ::std::fmt::Write as _; let _ = ::std::write!($buf, $lit $($arg)*); } | ||
25 | }; | ||
26 | } | ||
27 | |||
28 | pub trait SepBy: Sized { | 11 | pub trait SepBy: Sized { |
29 | /// Returns an `impl fmt::Display`, which joins elements via a separator. | 12 | /// Returns an `impl fmt::Display`, which joins elements via a separator. |
30 | fn sep_by<'a>(self, sep: &'a str) -> SepByBuilder<'a, Self>; | 13 | fn sep_by<'a>(self, sep: &'a str) -> SepByBuilder<'a, Self>; |
@@ -87,6 +70,8 @@ where | |||
87 | Ok(()) | 70 | Ok(()) |
88 | } | 71 | } |
89 | } | 72 | } |
73 | |||
74 | #[must_use] | ||
90 | pub fn timeit(label: &'static str) -> impl Drop { | 75 | pub fn timeit(label: &'static str) -> impl Drop { |
91 | struct Guard { | 76 | struct Guard { |
92 | label: &'static str, | 77 | label: &'static str, |