diff --git a/crates/polychem/src/atoms/particle.rs b/crates/polychem/src/atoms/particle.rs index 7b6e1b0..21a6e51 100644 --- a/crates/polychem/src/atoms/particle.rs +++ b/crates/polychem/src/atoms/particle.rs @@ -1,3 +1,5 @@ +use std::fmt::{self, Display, Formatter}; + use rust_decimal::Decimal; use crate::{Charge, Charged, Massive, Mz, Particle}; @@ -26,6 +28,13 @@ impl<'a> Particle<'a> { } } +impl Display for Particle<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + let symbol = self.symbol; + write!(f, "{symbol}") + } +} + impl Massive for Particle<'_> { fn monoisotopic_mass(&self) -> Decimal { *self.mass @@ -65,6 +74,14 @@ mod tests { assert_miette_snapshot!(Particle::new(&DB, "m")); } + #[test] + fn particle_display() { + let p = Particle::new(&DB, "p").unwrap(); + assert_eq!(p.to_string(), "p"); + let e = Particle::new(&DB, "e").unwrap(); + assert_eq!(e.to_string(), "e"); + } + #[test] fn particle_masses() { let proton = Particle::new(&DB, "p").unwrap();