Expand description
Format trait for an empty format, {}
.
Display
is similar to Debug
, but Display
is for user-facing
output, and so cannot be derived.
For more information on formatters, see the module-level documentation.
Implementing Display
on a type:
use std::fmt;
struct Point {
x: i32,
y: i32,
}
impl fmt::Display for Point {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {})", self.x, self.y)
}
}
let origin = Point { x: 0, y: 0 };
assert_eq!(format!("The origin is: {}", origin), "The origin is: (0, 0)");
Formats the value using the given formatter.
use std::fmt;
struct Position {
longitude: f32,
latitude: f32,
}
impl fmt::Display for Position {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {})", self.longitude, self.latitude)
}
}
assert_eq!("(1.987, 2.983)",
format!("{}", Position { longitude: 1.987, latitude: 2.983, }));
impl<'rwlock, T, R> Display for RwLockUpgradableGuard<'rwlock, T, R> where
T: Display + ?Sized,
impl<'a, R, T> Display for MappedMutexGuard<'a, R, T> where
R: 'a + RawMutex,
T: 'a + Display + ?Sized,
impl<'a, R, T> Display for MappedRwLockWriteGuard<'a, R, T> where
R: 'a + RawRwLock,
T: 'a + Display + ?Sized,
impl<'a, R, G, T> Display for MappedReentrantMutexGuard<'a, R, G, T> where
R: 'a + RawMutex,
G: 'a + GetThreadId,
T: 'a + Display + ?Sized,
impl<'a, R, T> Display for MutexGuard<'a, R, T> where
R: 'a + RawMutex,
T: 'a + Display + ?Sized,
impl<'a, R, T> Display for RwLockUpgradableReadGuard<'a, R, T> where
R: 'a + RawRwLockUpgrade,
T: 'a + Display + ?Sized,
impl<'a, R, T> Display for RwLockReadGuard<'a, R, T> where
R: 'a + RawRwLock,
T: 'a + Display + ?Sized,
impl<'a, R, T> Display for MappedRwLockReadGuard<'a, R, T> where
R: 'a + RawRwLock,
T: 'a + Display + ?Sized,
impl<'a, R, T> Display for RwLockWriteGuard<'a, R, T> where
R: 'a + RawRwLock,
T: 'a + Display + ?Sized,
impl<'a, R, G, T> Display for ReentrantMutexGuard<'a, R, G, T> where
R: 'a + RawMutex,
G: 'a + GetThreadId,
T: 'a + Display + ?Sized,
impl<'a, K, V, S, A> Display for OccupiedError<'a, K, V, S, A> where
K: Debug,
V: Debug,
A: Allocator + Clone,