Mon, 21 Oct 2024 09:59:45 -0500
Implement Display for Loc
src/loc.rs | file | annotate | diff | comparison | revisions |
--- a/src/loc.rs Mon Oct 21 09:11:34 2024 -0500 +++ b/src/loc.rs Mon Oct 21 09:59:45 2024 -0500 @@ -5,6 +5,7 @@ use std::ops::{Add,Sub,AddAssign,SubAssign,Mul,Div,MulAssign,DivAssign,Neg,Index,IndexMut}; use std::slice::{Iter,IterMut}; +use std::fmt::{Display, Formatter}; use crate::types::{Float,Num,SignedNum}; use crate::maputil::{FixedLength,FixedLengthMut,map1,map2,map1_mut,map2_mut}; use crate::euclidean::*; @@ -22,6 +23,19 @@ pub [F; N] ); +impl<F : Display, const N : usize> Display for Loc<F, N>{ + // Required method + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "[")?; + let mut comma = ""; + for e in self.iter() { + write!(f, "{comma}{e}")?; + comma = ", "; + } + write!(f, "]") + } +} + // Need to manually implement as [F; N] serialisation is provided only for some N. impl<F, const N : usize> Serialize for Loc<F, N> where