Skip to content

Commit 0877353

Browse files
authored
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.
1 parent cb86abf commit 0877353

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ macro_rules! impl_id_traits {
281281
impl std::fmt::Display for $idtype {
282282
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
283283
match *self == Self::NULL {
284-
false => write!(f, "{}({})", stringify!($idtype), self.0),
285-
true => write!(f, "{}(NULL)", stringify!($idtype)),
284+
false => write!(f, "{}", self.0),
285+
true => write!(f, "NULL"),
286286
}
287287
}
288288
}

src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,12 @@ use bindings::tsk_size_t;
158158
/// use tskit::NodeId;
159159
///
160160
/// let n = NodeId::from(11);
161-
/// assert_eq!(format!("{}", n), "NodeId(11)".to_string());
161+
/// assert_eq!(format!("{}", n), "11".to_string());
162+
/// // Debug output contains type info
163+
/// assert_eq!(format!("{:?}", n), "NodeId(11)".to_string());
162164
/// let n = NodeId::from(NodeId::NULL);
163-
/// assert_eq!(format!("{}", n), "NodeId(NULL)".to_string());
165+
/// assert_eq!(format!("{}", n), "NULL");
166+
/// assert_eq!(format!("{:?}", n), "NodeId(-1)");
164167
/// ```
165168
///
166169
#[repr(transparent)]

0 commit comments

Comments
 (0)