Skip to content

Commit

Permalink
refactor: Display for new types now omits type name. (#305)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: will break code that relies on the
type info being present in non-debug output.
  • Loading branch information
molpopgen authored Jul 30, 2022
1 parent cb86abf commit 0877353
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit 0877353

Please sign in to comment.