We want it there for hacking about, at least.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
impl<T:Debug> T {
fn to_debug(&self) -> String { format!("{:?}", self) }
}
+
+pub fn dbgc_helper(file: &'static str, line: u32,
+ values: &[(&'static str, &dyn Debug)]) {
+ let buf = (||{
+ let mut buf = String::new();
+ write!(buf, "[{}:{}]", file, line)?;
+ for (s, v) in values.iter() {
+ write!(buf, " {}={:?}", s, v)?;
+ }
+ write!(buf, "\n")?;
+ Ok::<_,fmt::Error>(buf)
+ })();
+ let buf = buf.unwrap_or_else(
+ |e| format!("error formatting for dbgc! {}\n", e));
+ eprint!("{}", buf);
+}
+
+#[macro_export]
+macro_rules! dbgc {
+ // NOTE: We cannot use `concat!` to make a static string as a format argument
+ // of `eprintln!` because `file!` could contain a `{` or
+ // `$val` expression could be a block (`{ .. }`), in which case the `eprintln!`
+ // will be malformed.
+ () => {
+ dbgc_helper(std::file!(), std::line!(), &[])
+ };
+ ($val:expr $(,)?) => {
+ // Use of `match` here is intentional because it affects the lifetimes
+ // of temporaries - https://stackoverflow.com/a/48732525/1063961
+ match $val {
+ tmp => {
+ dbgc_helper(std::file!(), std::line!(),
+ &[(std::stringify!($val), &tmp)]);
+ tmp
+ }
+ }
+ };
+ ($($val:expr),+ $(,)?) => {
+ dbgc_helper(std::file!(), std::line!(),
+ &[$((std::stringify!($val), &$val)),+])
+ };
+}
pub use std::borrow::Borrow;
pub use std::cmp::{max, Ordering};
pub use std::convert::{TryFrom, TryInto};
-pub use std::fmt::{self, Debug, Display, Formatter};
+pub use std::fmt::{self, Debug, Display, Formatter, Write as _};
pub use std::hash::{Hash, Hasher};
pub use std::iter;
pub use std::mem;
pub use otter_base::geometry::{CoordinateOverflow,Region};
pub use otter_base::zcoord::{self, ZCoord};
pub use otter_base::misc as base_misc;
+pub use otter_base::dbgc;
pub use base_misc::*;
-pub use crate::dbgc;
pub use crate::{deref_to_field, deref_to_field_mut};
pub use crate::ensure_eq;
pub use crate::format_by_fmt_hex;
);
}
-pub fn dbgc_helper(file: &'static str, line: u32,
- values: &[(&'static str, &dyn Debug)]) {
- let buf = (||{
- let mut buf = String::new();
- write!(buf, "[{}:{}]", file, line)?;
- for (s, v) in values.iter() {
- write!(buf, " {}={:?}", s, v)?;
- }
- write!(buf, "\n")?;
- Ok::<_,fmt::Error>(buf)
- })();
- let buf = buf.unwrap_or_else(
- |e| format!("error formatting for dbgc! {}\n", e));
- eprint!("{}", buf);
-}
-
-#[macro_export]
-macro_rules! dbgc {
- // NOTE: We cannot use `concat!` to make a static string as a format argument
- // of `eprintln!` because `file!` could contain a `{` or
- // `$val` expression could be a block (`{ .. }`), in which case the `eprintln!`
- // will be malformed.
- () => {
- dbgc_helper(std::file!(), std::line!(), &[])
- };
- ($val:expr $(,)?) => {
- // Use of `match` here is intentional because it affects the lifetimes
- // of temporaries - https://stackoverflow.com/a/48732525/1063961
- match $val {
- tmp => {
- dbgc_helper(std::file!(), std::line!(),
- &[(std::stringify!($val), &tmp)]);
- tmp
- }
- }
- };
- ($($val:expr),+ $(,)?) => {
- dbgc_helper(std::file!(), std::line!(),
- &[$((std::stringify!($val), &$val)),+])
- };
-}
-
#[macro_export]
macro_rules! trace_dbg {
($msg:expr $(,$val:expr)*) => {