From 0877353139d5a0bfd76f0a1eec78f044356423e8 Mon Sep 17 00:00:00 2001 From: "Kevin R. Thornton" Date: Fri, 29 Jul 2022 17:24:40 -0700 Subject: [PATCH] refactor: Display for new types now omits type name. (#305) BREAKING CHANGE: will break code that relies on the type info being present in non-debug output. --- src/_macros.rs | 4 ++-- src/lib.rs | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/_macros.rs b/src/_macros.rs index c3dae2e4..37a7da71 100644 --- a/src/_macros.rs +++ b/src/_macros.rs @@ -281,8 +281,8 @@ macro_rules! impl_id_traits { impl std::fmt::Display for $idtype { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match *self == Self::NULL { - false => write!(f, "{}({})", stringify!($idtype), self.0), - true => write!(f, "{}(NULL)", stringify!($idtype)), + false => write!(f, "{}", self.0), + true => write!(f, "NULL"), } } } diff --git a/src/lib.rs b/src/lib.rs index d45f0634..50106db0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -158,9 +158,12 @@ use bindings::tsk_size_t; /// use tskit::NodeId; /// /// let n = NodeId::from(11); -/// assert_eq!(format!("{}", n), "NodeId(11)".to_string()); +/// assert_eq!(format!("{}", n), "11".to_string()); +/// // Debug output contains type info +/// assert_eq!(format!("{:?}", n), "NodeId(11)".to_string()); /// let n = NodeId::from(NodeId::NULL); -/// assert_eq!(format!("{}", n), "NodeId(NULL)".to_string()); +/// assert_eq!(format!("{}", n), "NULL"); +/// assert_eq!(format!("{:?}", n), "NodeId(-1)"); /// ``` /// #[repr(transparent)]