Skip to content

Commit

Permalink
EntityId display (#69)
Browse files Browse the repository at this point in the history
* chore: entity id display

* chore: add comments to display impl
  • Loading branch information
Roms1383 authored Dec 12, 2024
1 parent a1b7915 commit 3c6edb1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/types/entity_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,36 @@ impl fmt::Debug for EntityId {
.finish_non_exhaustive()
}
}

/// A simple entity ID representation.
///
/// Flags are displayed as:
/// - `P`ersistable
/// - `D`ynamic
/// - `T`ransient
/// - `S`tatic
impl std::fmt::Display for EntityId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match (self.is_defined(), self.is_persistable()) {
(true, persistable) => {
write!(
f,
"{} {}",
self.0.hash,
match (persistable, self.is_dynamic(), self.is_transient()) {
(true, true, true) => "(P|D|T)",
(true, true, false) => "(P|D)",
(true, false, true) => "(P|S|T)",
(true, false, false) => "(P|S)",
(false, true, true) => "(D|T)",
(false, true, false) => "(D)",
(false, false, true) => "(S|T)",
(false, false, false) => "(S)",
}
)
}
(false, false) => write!(f, "undefined"),
(false, true) => write!(f, "undefined (P)"),
}
}
}

0 comments on commit 3c6edb1

Please sign in to comment.