Skip to content

Commit

Permalink
feat(polychem): add Display impl for Particle
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLostLambda committed Mar 27, 2024
1 parent 4593f95 commit e17abce
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/polychem/src/atoms/particle.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{self, Display, Formatter};

use rust_decimal::Decimal;

use crate::{Charge, Charged, Massive, Mz, Particle};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e17abce

Please sign in to comment.