Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ 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)),
}
}
}

impl From<$crate::tsk_id_t> for $idtype {
fn from(value: $crate::tsk_id_t) -> Self {
Self(value)
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ pub use bindings::tsk_size_t;
/// assert_eq!(interesting(x), x);
/// ```
///
/// The types also implement `Display`:
///
/// ```
/// use tskit::NodeId;
///
/// let n = NodeId::from(11);
/// assert_eq!(format!("{}", n), "NodeId(11)".to_string());
/// let n = NodeId::from(NodeId::NULL);
/// assert_eq!(format!("{}", n), "NodeId(NULL)".to_string());
/// ```
///
#[repr(transparent)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, std::hash::Hash)]
pub struct NodeId(tsk_id_t);
Expand Down
6 changes: 0 additions & 6 deletions src/provenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ impl PartialEq for ProvenanceTableRow {
}
}

impl std::fmt::Display for ProvenanceId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "ProvenanceId({})", self.0)
}
}

impl std::fmt::Display for ProvenanceTableRow {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
Expand Down