Rust — how to print arbitrary object

Water_J
Jan 2, 2021
use std::fmt;struct Point<T, U> {
x: T,
y: U,
}
# impl<T: fmt::Display, U: fmt::Display> fmt::Display for Point<T, U>
impl<T, U> fmt::Display for Point<T, U>
where
T: fmt::Display,
U: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, “({}, {})”, self.x, self.y)
}
}

--

--