pub trait Display {
// Required method
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>;
}Expand description
Format trait for an empty format, {}.
Implementing this trait for a type will automatically implement the
ToString trait for the type, allowing the usage
of the .to_string() method. Prefer implementing
the Display trait for a type, rather than ToString.
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.
§Completeness and parseability
Display for a type might not necessarily be a lossless or complete representation of the type.
It may omit internal state, precision, or other information the type does not consider important
for user-facing output, as determined by the type. As such, the output of Display might not be
possible to parse, and even if it is, the result of parsing might not exactly match the original
value.
However, if a type has a lossless Display implementation whose output is meant to be
conveniently machine-parseable and not just meant for human consumption, then the type may wish
to accept the same format in FromStr, and document that usage. Having both Display and
FromStr implementations where the result of Display cannot be parsed with FromStr may
surprise users.
§Internationalization
Because a type can only have one Display implementation, it is often preferable
to only implement Display when there is a single most “obvious” way that
values can be formatted as text. This could mean formatting according to the
“invariant” culture and “undefined” locale, or it could mean that the type
display is designed for a specific culture/locale, such as developer logs.
If not all values have a justifiably canonical textual format or if you want
to support alternative formats not covered by the standard set of possible
formatting traits, the most flexible approach is display adapters: methods
like str::escape_default or Path::display which create a wrapper
implementing Display to output the specific display format.
§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§
1.0.0 · Sourcefn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Formats the value using the given formatter.
§Errors
This function should return Err if, and only if, the provided Formatter returns Err.
String formatting is considered an infallible operation; this function only
returns a Result because writing to the underlying stream might fail and it must
provide a way to propagate the fact that an error has occurred back up the stack.
§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, }),
);Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl Display for !
impl Display for AccessError
impl Display for AcquireError
impl Display for core::net::parser::AddrParseError
impl Display for rustls_pki_types::server_name::AddrParseError
impl Display for AllocError
impl Display for Arguments<'_>
impl Display for AsciiChar
impl Display for http_type::attribute::enum::Attribute
impl Display for icu_locale_core::extensions::unicode::attribute::Attribute
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for xml::attribute::Attribute<'_>
impl Display for Attributes
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for Backtrace
impl Display for BernoulliError
impl Display for BorrowError
impl Display for BorrowMutError
impl Display for ByteStr
impl Display for ByteString
impl Display for CertificateError
impl Display for CharTryFromError
impl Display for CollectionAllocErr
impl Display for Compress
Implements the Display trait for the Compress enum.
This allows the Compress enum variants to be formatted as strings,
typically used for outputting the Content-Encoding header value.
impl Display for CompressError
impl Display for CurrencyType
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for DataError
impl Display for DataErrorKind
impl Display for DataIdentifierBorrowed<'_>
impl Display for DataLocale
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for DecodeUtf16Error
impl Display for flate2::mem::DecompressError
impl Display for miniz_oxide::inflate::DecompressError
with-alloc only.impl Display for std::ffi::os_str::Display<'_>
impl Display for std::path::Display<'_>
impl Display for core::ffi::c_str::Display<'_>
impl Display for EarlyDataError
impl Display for Elapsed
impl Display for EmitterError
impl Display for Empty
impl Display for EncodeError
impl Display for Encoding
impl Display for EncryptError
impl Display for Errno
impl Display for core::io::error::Error
impl Display for http_request::self::Error
impl Display for rand::distr::uniform::Error
impl Display for rand::distr::weighted::Error
impl Display for getrandom::error::Error
impl Display for serde_json::error::Error
impl Display for serde_core::de::value::Error
impl Display for tokio::time::error::Error
impl Display for icu_collections::codepointtrie::error::Error
impl Display for serde_xml_rs::error::Error
impl Display for xml::reader::error::Error
impl Display for serde_urlencoded::ser::Error
impl Display for rustls::error::Error
impl Display for rustls_pki_types::pem::Error
impl Display for getrandom::error::Error
impl Display for webpki::error::Error
impl Display for ErrorKind
impl Display for Errors
impl Display for core::char::EscapeDebug
impl Display for core::ascii::EscapeDefault
impl Display for core::char::EscapeDefault
impl Display for core::char::EscapeUnicode
impl Display for ExitStatus
impl Display for ExitStatusError
impl Display for ExtendedKeyPurpose
impl Display for Extensions
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for Fields
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for FileExtension
impl Display for FromBytesUntilNulError
impl Display for FromBytesWithNulError
impl Display for FromHexError
impl Display for FromUtf8Error
impl Display for FromUtf16Error
impl Display for FromVecWithNulError
impl Display for GetDisjointMutError
impl Display for HttpStatus
Implements the Display trait for HttpStatus, allowing it to be formatted as a string.
impl Display for HttpUrlError
Implements the Display trait for HttpUrlError, allowing it to be formatted as a string.
impl Display for HttpVersion
Implements the Display trait for HttpVersion, allowing it to be formatted as a string.
impl Display for tokio::runtime::task::id::Id
impl Display for tokio::runtime::id::Id
impl Display for ImmutableEntitiesError
impl Display for InternalAttribute
impl Display for IntoStringError
impl Display for InvalidDnsNameError
impl Display for InvalidSetError
impl Display for InvalidStringList
impl Display for IpAddr
impl Display for Ipv4Addr
impl Display for Ipv6Addr
Writes an Ipv6Addr, conforming to the canonical style described by RFC 5952.
impl Display for JoinError
impl Display for JoinPathsError
impl Display for icu_locale_core::extensions::transform::key::Key
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for icu_locale_core::extensions::unicode::key::Key
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for KeyRejected
impl Display for Keywords
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for Language
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for LanguageIdentifier
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for LayoutError
impl Display for Level
impl Display for LevelFilter
impl Display for Locale
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for Location<'_>
impl Display for Method
Implements the Display trait for Method, allowing it to be formatted as a string.
impl Display for Name<'_>
impl Display for NormalizeError
impl Display for NulError
impl Display for Number
impl Display for OneshotWithSecretError
impl Display for Other
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for OtherError
impl Display for OwnedAttribute
impl Display for OwnedName
impl Display for PanicData
impl Display for PanicHookInfo<'_>
impl Display for PanicInfo<'_>
impl Display for PanicMessage<'_>
impl Display for ParseBoolError
impl Display for ParseCharError
impl Display for url::parser::ParseError
impl Display for icu_locale_core::parser::errors::ParseError
impl Display for tinystr::error::ParseError
impl Display for ParseFloatError
impl Display for ParseIntError
impl Display for ParseLevelError
impl Display for PercentEncode<'_>
impl Display for PreferencesParseError
impl Display for Private
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for RangeError
impl Display for std::sync::mpsc::RecvError
impl Display for tokio::sync::broadcast::error::RecvError
impl Display for tokio::sync::oneshot::error::RecvError
impl Display for tokio::sync::watch::error::RecvError
impl Display for std::sync::mpsc::RecvTimeoutError
impl Display for Region
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for Request
impl Display for RequestConfig
impl Display for RequestError
impl Display for Response
impl Display for ResponseError
Implements the Display trait for ResponseError.
This allows ResponseError variants to be formatted into human-readable strings.
impl Display for tokio::net::tcp::split_owned::ReuniteError
impl Display for tokio::net::unix::split_owned::ReuniteError
impl Display for Script
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for SetLoggerError
impl Display for SocketAddr
impl Display for SocketAddrV4
impl Display for SocketAddrV6
impl Display for Stream
impl Display for String
impl Display for StripPrefixError
impl Display for SubdivisionId
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for SubdivisionSuffix
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for icu_locale_core::extensions::private::other::Subtag
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for icu_locale_core::subtags::Subtag
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for SyntaxViolation
impl Display for SystemTimeError
impl Display for Task
impl Display for TextPosition
impl Display for ToCasefold
impl Display for ToLowercase
impl Display for ToTitlecase
impl Display for ToUppercase
impl Display for Transform
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for TryAcquireError
impl Display for TryCurrentError
impl Display for TryFromCharError
impl Display for TryFromFloatSecsError
impl Display for TryFromIntError
impl Display for TryFromSliceError
impl Display for TryGetError
impl Display for std::fs::TryLockError
impl Display for tokio::sync::mutex::TryLockError
impl Display for std::sync::mpsc::TryRecvError
impl Display for tokio::sync::broadcast::error::TryRecvError
impl Display for tokio::sync::mpsc::error::TryRecvError
impl Display for tokio::sync::oneshot::error::TryRecvError
impl Display for TryReserveError
impl Display for UleError
impl Display for Unicode
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for UnorderedKeyError
impl Display for Unspecified
impl Display for UnsupportedOperationError
impl Display for UpgradeType
Implements the Display trait for UpgradeType.
This allows UpgradeType variants to be formatted into human-readable strings.
impl Display for Url
Display the serialization of this URL.
impl Display for Utf8CharsError
impl Display for Utf8Error
impl Display for serde_json::value::Value
impl Display for icu_locale_core::extensions::transform::value::Value
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for icu_locale_core::extensions::unicode::value::Value
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for VarError
impl Display for Variant
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for Variants
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl Display for VerifierBuilderError
impl Display for WebSocketFrame
impl Display for WouldBlock
impl Display for WriterPanicked
impl Display for XmlVersion
impl Display for ZeroTrieBuildError
impl Display for bool
impl Display for char
impl Display for dyn Expected + '_
impl Display for f16
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 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<'a, 'b> Display for ReprDisplay<'a, 'b>where
'b: 'a,
impl<'a, A, C> Display for Replace<A, &'a str, C>
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl<'a, R, G, T> Display for MappedReentrantMutexGuard<'a, R, G, T>
impl<'a, R, G, T> Display for ReentrantMutexGuard<'a, R, G, T>
impl<'a, R, T> Display for lock_api::mutex::MappedMutexGuard<'a, R, T>
impl<'a, R, T> Display for lock_api::rwlock::MappedRwLockReadGuard<'a, R, T>
impl<'a, R, T> Display for lock_api::rwlock::MappedRwLockWriteGuard<'a, R, T>
impl<'a, R, T> Display for lock_api::mutex::MutexGuard<'a, R, T>
impl<'a, R, T> Display for lock_api::rwlock::RwLockReadGuard<'a, R, T>
impl<'a, R, T> Display for RwLockUpgradableReadGuard<'a, R, T>
impl<'a, R, T> Display for lock_api::rwlock::RwLockWriteGuard<'a, R, T>
impl<'a, T> Display for tokio::sync::mutex::MappedMutexGuard<'a, T>
impl<'a, T> Display for RwLockMappedWriteGuard<'a, T>
impl<'a, T> Display for tokio::sync::rwlock::read_guard::RwLockReadGuard<'a, T>
impl<'a, T> Display for tokio::sync::rwlock::write_guard::RwLockWriteGuard<'a, T>
impl<'a> Display for EscapeAscii<'a>
impl<'a> Display for core::str::iter::EscapeDebug<'a>
impl<'a> Display for core::str::iter::EscapeDefault<'a>
impl<'a> Display for core::str::iter::EscapeUnicode<'a>
impl<'a> Display for Unexpected<'a>
impl<A, B> Display for Concat<A, B>
impl<B> Display for Cow<'_, B>
impl<E> Display for Report<E>where
E: Error,
impl<F> Display for FromFn<F>
impl<Ptr> Display for Pin<Ptr>where
Ptr: Display,
impl<S> Display for Host<S>
impl<S> Display for SecretTooShortError<S>
impl<S> Display for SecretWithSeedError<S>
impl<T, A> Display for Arc<T, A>
impl<T, A> Display for Box<T, A>
impl<T, A> Display for Rc<T, A>
impl<T, A> Display for UniqueArc<T, A>
impl<T, A> Display for UniqueRc<T, A>
impl<T, U> Display for OwnedMappedMutexGuard<T, U>
impl<T, U> Display for OwnedRwLockMappedWriteGuard<T, U>
impl<T, U> Display for OwnedRwLockReadGuard<T, U>
impl<T> Display for &T
impl<T> Display for &mut T
impl<T> Display for AsyncFdTryNewError<T>
impl<T> Display for LossyWrap<T>where
T: TryWriteable,
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
impl<T> Display for std::sync::nonpoison::mutex::MappedMutexGuard<'_, T>
impl<T> Display for std::sync::poison::mutex::MappedMutexGuard<'_, T>
impl<T> Display for std::sync::nonpoison::rwlock::MappedRwLockReadGuard<'_, T>
impl<T> Display for std::sync::poison::rwlock::MappedRwLockReadGuard<'_, T>
impl<T> Display for std::sync::nonpoison::rwlock::MappedRwLockWriteGuard<'_, T>
impl<T> Display for std::sync::poison::rwlock::MappedRwLockWriteGuard<'_, T>
impl<T> Display for std::sync::nonpoison::mutex::MutexGuard<'_, T>
impl<T> Display for std::sync::poison::mutex::MutexGuard<'_, T>
impl<T> Display for tokio::sync::mutex::MutexGuard<'_, T>
impl<T> Display for NonZero<T>where
T: ZeroablePrimitive + Display,
impl<T> Display for OwnedMutexGuard<T>
impl<T> Display for OwnedRwLockWriteGuard<T>
impl<T> Display for PoisonError<T>
impl<T> Display for std::sync::oneshot::RecvTimeoutError<T>
impl<T> Display for ReentrantLockGuard<'_, T>
impl<T> Display for Ref<'_, T>
impl<T> Display for RefMut<'_, T>
impl<T> Display for std::sync::nonpoison::rwlock::RwLockReadGuard<'_, T>
impl<T> Display for std::sync::poison::rwlock::RwLockReadGuard<'_, T>
impl<T> Display for std::sync::nonpoison::rwlock::RwLockWriteGuard<'_, T>
impl<T> Display for std::sync::poison::rwlock::RwLockWriteGuard<'_, T>
impl<T> Display for Saturating<T>where
T: Display,
impl<T> Display for std::sync::mpsc::SendError<T>
impl<T> Display for tokio::sync::broadcast::error::SendError<T>
impl<T> Display for tokio::sync::mpsc::error::SendError<T>
impl<T> Display for tokio::sync::watch::error::SendError<T>
impl<T> Display for std::sync::mpmc::error::SendTimeoutError<T>
impl<T> Display for tokio::sync::mpsc::error::SendTimeoutError<T>
time only.impl<T> Display for SetError<T>
impl<T> Display for SetOnceError<T>
impl<T> Display for ThinBox<T>
impl<T> Display for std::sync::poison::TryLockError<T>
impl<T> Display for std::sync::oneshot::TryRecvError<T>
impl<T> Display for std::sync::mpsc::TrySendError<T>
impl<T> Display for tokio::sync::mpsc::error::TrySendError<T>
impl<T> Display for TryWriteableInfallibleAsWriteable<T>where
T: TryWriteable<Error = !>,
impl<T> Display for WithPart<T>
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.