Trait std::fmt::Display
pub trait Display { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>; }
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.
Examples
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)");
Required methods
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Formats the value using the given formatter.
Examples
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, }));
Implementations on Foreign Types
impl Display for FromSecsError
pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
impl<'a> Display for EscapeAscii<'a>
pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
impl Display for Utf8Lossy
pub fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Implementors
[src]1.34.0
impl Display for Infallible
impl Display for VarError
[src]1.7.0
impl Display for IpAddr
impl Display for SocketAddr
[src]1.15.0
impl Display for RecvTimeoutError
impl Display for TryRecvError
impl Display for bool
impl Display for char
impl Display for f32
impl Display for f64
impl Display for i8
impl Display for i16
impl Display for i32
impl Display for i64
impl Display for i128
impl Display for isize
impl Display for !
impl Display for str
impl Display for u8
impl Display for u16
impl Display for u32
impl Display for u64
impl Display for u128
impl Display for usize
impl Display for AllocError
[src]1.28.0
impl Display for LayoutError
[src]1.36.0
impl Display for TryFromSliceError
[src]1.39.0
impl Display for std::ascii::EscapeDefault
impl Display for Backtrace
[src]1.13.0
impl Display for BorrowError
[src]1.13.0
impl Display for BorrowMutError
[src]1.34.0
impl Display for CharTryFromError
[src]1.9.0
impl Display for DecodeUtf16Error
[src]1.20.0
impl Display for std::char::EscapeDebug
[src]1.16.0
impl Display for std::char::EscapeDefault
[src]1.16.0
impl Display for std::char::EscapeUnicode
[src]1.20.0
impl Display for ParseCharError
[src]1.16.0
impl Display for ToLowercase
[src]1.16.0
impl Display for ToUppercase
impl Display for TryReserveError
impl Display for JoinPathsError
[src]1.17.0
impl Display for FromBytesWithNulError
impl Display for FromVecWithNulError
[src]1.7.0
impl Display for IntoStringError
impl Display for NulError
impl Display for std::io::Error
[src]1.56.0
impl Display for WriterPanicked
[src]1.4.0
impl Display for AddrParseError
impl Display for Ipv4Addr
impl Display for Ipv6Addr
Write an Ipv6Addr, conforming to the canonical style described by RFC 5952.
impl Display for SocketAddrV4
impl Display for SocketAddrV6
[src]1.34.0
impl Display for NonZeroI8
[src]1.34.0
impl Display for NonZeroI16
[src]1.34.0
impl Display for NonZeroI32
[src]1.34.0
impl Display for NonZeroI64
[src]1.34.0
impl Display for NonZeroI128
[src]1.34.0
impl Display for NonZeroIsize
[src]1.28.0
impl Display for NonZeroU8
[src]1.28.0
impl Display for NonZeroU16
[src]1.28.0
impl Display for NonZeroU32
[src]1.28.0
impl Display for NonZeroU64
[src]1.28.0
impl Display for NonZeroU128
[src]1.28.0
impl Display for NonZeroUsize
impl Display for ParseFloatError
impl Display for ParseIntError
[src]1.34.0
impl Display for TryFromIntError
impl Display for Display<'_>
[src]1.7.0
impl Display for StripPrefixError
impl Display for ExitStatus
impl Display for ExitStatusError
impl Display for ParseBoolError
impl Display for Utf8Error
impl Display for FromUtf8Error
impl Display for FromUtf16Error
impl Display for String
impl Display for RecvError
[src]1.26.0
impl Display for AccessError
[src]1.8.0
impl Display for SystemTimeError
impl Display for std::fmt::Error
[src]1.26.0
impl<'_> Display for Location<'_>
[src]1.26.0
impl<'_> Display for PanicInfo<'_>
impl<'_> Display for Arguments<'_>
impl<'_, B> Display for Cow<'_, B> where
B: Display + ToOwned + ?Sized,
<B as ToOwned>::Owned: Display,
[src]1.34.0
impl<'a> Display for std::str::EscapeDebug<'a>
[src]1.34.0
impl<'a> Display for std::str::EscapeDefault<'a>
[src]1.34.0
impl<'a> Display for std::str::EscapeUnicode<'a>
impl<'a, K, V> Display for std::collections::btree_map::OccupiedError<'a, K, V> where
K: Debug + Ord,
V: Debug,
impl<'a, K: Debug, V: Debug> Display for std::collections::hash_map::OccupiedError<'a, K, V>
impl<T> Display for TryLockError<T>
impl<T> Display for TrySendError<T>
impl<T> Display for SendError<T>
impl<T> Display for PoisonError<T>
[src]1.20.0
impl<T: ?Sized + Display> Display for MutexGuard<'_, T>
[src]1.20.0
impl<T: ?Sized + Display> Display for RwLockReadGuard<'_, T>
[src]1.20.0
impl<T: ?Sized + Display> Display for RwLockWriteGuard<'_, T>
impl<W> Display for IntoInnerError<W>
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/fmt/trait.Display.html