Skip to content

Commit

Permalink
make OPoint call T::fmt to respect formatting modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtlawrence committed Dec 20, 2023
1 parent 1e0cb7b commit 90b49a7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/geometry/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,26 @@ where

let mut it = self.coords.iter();

write!(f, "{}", *it.next().unwrap())?;
<T as fmt::Display>::fmt(it.next().unwrap(), f)?;

for comp in it {
write!(f, ", {}", *comp)?;
write!(f, ", ")?;
<T as fmt::Display>::fmt(comp, f)?;
}

write!(f, "}}")
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn display_fmt_respects_modifiers() {
let p = crate::Point3::new(1.23, 3.45, 5.67);
assert_eq!(&format!("{p}"), "{1.23, 3.45, 5.67}");
assert_eq!(&format!("{p:.1}"), "{1.2, 3.5, 5.7}");
assert_eq!(&format!("{p:.0}"), "{1, 3, 6}");
}
}

0 comments on commit 90b49a7

Please sign in to comment.