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 AddrParseError
impl Display for AllocError
impl Display for Arg
impl Display for Arguments<'_>
impl Display for AsciiChar
impl Display for Ast
Print a display representation of this Ast.
This does not preserve any of the original whitespace formatting that may have originally been present in the concrete syntax from which this Ast was generated.
This implementation uses constant stack space and heap space proportional
to the size of the Ast.
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 BStr
impl Display for BString
impl Display for Backtrace
impl Display for BernoulliError
impl Display for BorrowError
impl Display for BorrowMutError
impl Display for Buffer
impl Display for regex_automata::dfa::onepass::BuildError
impl Display for regex_automata::hybrid::error::BuildError
impl Display for regex_automata::meta::error::BuildError
impl Display for regex_automata::nfa::thompson::error::BuildError
impl Display for aho_corasick::util::error::BuildError
impl Display for ByteStr
impl Display for ByteString
impl Display for winnow::stream::bytes::Bytes
impl Display for winnow::stream::bytes::Bytes
impl Display for CacheError
impl Display for CaseFoldError
impl Display for CharTryFromError
impl Display for CollectionAllocErr
impl Display for Color
impl Display for ColorChoice
impl Display for ColorType
impl Display for Command
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 Context
impl Display for ContextError
impl Display for ContextKind
impl Display for ContextValue
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 Date
impl Display for Datetime
alloc only.impl Display for DatetimeParseError
impl Display for DeFloat<'_>
impl Display for DeInteger<'_>
impl Display for DecodeUtf16Error
impl Display for flate2::mem::DecompressError
impl Display for miniz_oxide::inflate::DecompressError
with-alloc only.impl Display for DefaultServerHook
impl Display for DeserializeError
impl Display for std::ffi::os_str::Display<'_>
impl Display for std::path::Display<'_>
impl Display for Elapsed
impl Display for EmitterError
impl Display for Empty
impl Display for EmptyError
impl Display for Encoding
impl Display for Errno
impl Display for euv_cli::IoError
impl Display for core::fmt::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 regex::error::Error
impl Display for regex_syntax::ast::Error
impl Display for regex_syntax::error::Error
impl Display for regex_syntax::hir::Error
impl Display for ignore::Error
impl Display for globset::Error
impl Display for walkdir::error::Error
impl Display for notify::error::Error
impl Display for toml::de::error::Error
Displays a TOML parse error
§Example
TOML parse error at line 1, column 10
|
1 | 00:32:00.a999999
| ^
Unexpected a
Expected digit
While parsing a Time
While parsing a Date-Time
impl Display for toml::ser::error::Error
impl Display for which::error::Error
impl Display for core::io::error::ErrorKind
impl Display for clap_builder::error::kind::ErrorKind
impl Display for regex_syntax::ast::ErrorKind
impl Display for regex_syntax::hir::ErrorKind
impl Display for globset::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 EuvError
Implements Display for EuvError to provide human-readable error messages.
impl Display for EventMaskParseError
impl Display for ExitStatus
impl Display for ExitStatusError
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 euv_cli::FromUtf8Error
impl Display for bstr::ext_vec::FromUtf8Error
impl Display for FromUtf16Error
impl Display for FromVecWithNulError
impl Display for GetDisjointMutError
impl Display for Glob
impl Display for GroupInfoError
impl Display for Hir
Print a display representation of this Hir.
The result of this is a valid regular expression pattern string.
This implementation uses constant stack space and heap space proportional
to the size of the Hir.
impl Display for Hook
impl Display for HookType
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 clap_builder::util::id::Id
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 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 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 Map<String, Value>
display only.impl Display for regex_automata::util::search::MatchError
impl Display for aho_corasick::util::error::MatchError
impl Display for MatchesError
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 NewError
impl Display for NonFatalError
impl Display for NormalizeError
impl Display for NulError
impl Display for Number
impl Display for Offset
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 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 bitflags::parser::ParseError
impl Display for ParseFloatError
impl Display for ParseIntError
impl Display for ParseLevelError
impl Display for regex_automata::util::primitives::PatternIDError
impl Display for aho_corasick::util::primitives::PatternIDError
impl Display for PatternSetInsertError
alloc only.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 PublishError
impl Display for QrError
impl Display for winnow::stream::range::Range
impl Display for winnow::stream::range::Range
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 regex::regex::bytes::Regex
impl Display for regex::regex::string::Regex
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 Reset
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 RouteError
impl Display for RouteMatcher
impl Display for RoutePattern
impl Display for RouteSegment
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 SerializeError
impl Display for SerializerError
impl Display for Server
impl Display for ServerConfig
impl Display for ServerControlHook
impl Display for ServerError
impl Display for SetLoggerError
impl Display for SmallIndexError
impl Display for SocketAddr
impl Display for SocketAddrV4
impl Display for SocketAddrV6
impl Display for StartError
impl Display for regex_automata::util::primitives::StateIDError
impl Display for aho_corasick::util::primitives::StateIDError
impl Display for Str
impl Display for StrContext
impl Display for StrContextValue
impl Display for StrSimError
impl Display for Stream
impl Display for String
impl Display for StripPrefixError
impl Display for StrippedStr<'_>
impl Display for Style
impl Display for StyledStr
Color-unaware printing. Never uses coloring.
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 TemplateError
impl Display for TextPosition
impl Display for Time
alloc only.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 UnicodeWordBoundaryError
impl Display for UnicodeWordError
impl Display for UnorderedKeyError
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 core::str::error::Utf8Error
impl Display for bstr::utf8::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 toml::value::Value
display only.impl Display for ValueRange
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 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 EscapeBytes<'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 ErrMode<E>where
E: Debug,
impl<E> Display for Report<E>where
E: Error,
impl<F> Display for clap_builder::error::Error<F>where
F: ErrorFormatter,
impl<F> Display for FromFn<F>
impl<I, E> Display for winnow::error::ParseError<I, E>
impl<I, S> Display for winnow::stream::stateful::Stateful<I, S>where
I: Display,
impl<I, S> Display for winnow::stream::stateful::Stateful<I, S>where
I: Display,
impl<I> Display for InputError<I>
The Display implementation allows the std::error::Error implementation
impl<I> Display for winnow::stream::locating::LocatingSlice<I>where
I: Display,
impl<I> Display for winnow::stream::locating::LocatingSlice<I>where
I: Display,
impl<I> Display for winnow::stream::partial::Partial<I>where
I: Display,
impl<I> Display for winnow::stream::partial::Partial<I>where
I: Display,
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 CachePadded<T>where
T: Display,
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 ShardedLockReadGuard<'_, T>
impl<T> Display for ShardedLockWriteGuard<'_, T>
impl<T> Display for Spanned<T>where
T: Display,
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.