pub trait Display {
// Required method
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>;
}
mtls
only.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.
§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, }),
);
Implementors§
impl Display for &dyn Show
impl Display for CliColors
impl Display for rocket::error::ErrorKind
impl Display for Entity
impl Display for rocket::form::error::ErrorKind<'_>
impl Display for rocket::http::Method
impl Display for ProxyProto<'_>
impl Display for SameSite
impl Display for rocket::http::uri::Uri<'_>
impl Display for PathError
impl Display for Endpoint
impl Display for rocket::listener::Error
impl Display for rocket::serde::json::Value
impl Display for rocket::serde::msgpack::Error
impl Display for Variant
impl Display for Feature
impl Display for Sig
impl Display for rocket::tls::Error
tls
only.impl Display for rocket::mtls::Error
impl Display for PEMError
impl Display for X509Error
impl Display for rocket::mtls::x509::der_parser::asn1_rs::Class
impl Display for DerConstraint
impl Display for rocket::mtls::x509::der_parser::asn1_rs::Error
impl Display for SerializeError
impl Display for Infallible
impl Display for AsciiChar
impl Display for IpAddr
impl Display for SocketAddr
impl Display for VarError
impl Display for std::io::error::ErrorKind
impl Display for RecvTimeoutError
impl Display for std::sync::mpsc::TryRecvError
impl Display for ParseAlphabetError
impl Display for base64::decode::DecodeError
impl Display for DecodeSliceError
impl Display for EncodeSliceError
impl Display for const_oid::error::Error
impl Display for cookie::parse::ParseError
impl Display for KeyError
impl Display for CuckooError
impl Display for DecodeKind
impl Display for Actual
impl Display for figment::error::Kind
impl Display for figment::metadata::Source
Displays the source. Location and custom sources are displayed directly. File paths are displayed relative to the current working directory if the relative path is shorter than the complete path.
impl Display for httparse::Error
impl Display for InlinableString
impl Display for log::Level
impl Display for log::LevelFilter
impl Display for multer::error::Error
impl Display for rmp_serde::encode::Error
impl Display for BytesReadError
impl Display for ValueReadError
impl Display for webpki::error::Error
impl Display for EarlyDataError
impl Display for EncodeError
impl Display for EncryptError
impl Display for rustls::error::Error
impl Display for VerifierBuilderError
impl Display for DecoderError
impl Display for s2n_quic_core::connection::error::Error
impl Display for s2n_quic_core::connection::id::Error
impl Display for BuilderError
impl Display for DatagramError
impl Display for s2n_quic_core::endpoint::Location
impl Display for EndpointType
impl Display for s2n_quic_core::inet::ip::SocketAddress
impl Display for s2n_quic_core::query::Error
impl Display for StreamError
impl Display for s2n_quic_platform::bpf::cbpf::Alu
impl Display for s2n_quic_platform::bpf::cbpf::Class
impl Display for s2n_quic_platform::bpf::cbpf::Jump
impl Display for s2n_quic_platform::bpf::cbpf::Mode
impl Display for s2n_quic_platform::bpf::cbpf::Size
impl Display for s2n_quic_platform::bpf::common::Source
impl Display for s2n_quic_platform::bpf::ebpf::Alu
impl Display for s2n_quic_platform::bpf::ebpf::Class
impl Display for s2n_quic_platform::bpf::ebpf::Jump
impl Display for s2n_quic_platform::bpf::ebpf::Mode
impl Display for s2n_quic_platform::bpf::ebpf::Size
impl Display for Swap
impl Display for CollectionAllocErr
impl Display for time::error::Error
impl Display for Format
impl Display for InvalidFormatDescription
impl Display for Parse
impl Display for ParseFromDescription
impl Display for TryFromParsed
impl Display for Month
impl Display for Weekday
impl Display for AnyDelimiterCodecError
impl Display for LinesCodecError
impl Display for TryAcquireError
impl Display for tokio::sync::broadcast::error::RecvError
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 toml::value::Value
impl Display for Offset
impl Display for Item
impl Display for toml_edit::ser::Error
impl Display for toml_edit::value::Value
impl Display for ubyte::parse::Error
impl Display for winnow::error::ErrorKind
The Display implementation allows the std::error::Error
implementation
impl Display for StrContext
impl Display for StrContextValue
impl Display for rand::distributions::bernoulli::BernoulliError
impl Display for rand::distributions::bernoulli::BernoulliError
impl Display for rand::distributions::weighted::WeightedError
impl Display for rand::distributions::weighted_index::WeightedError
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 Ident
impl Display for rocket::config::Level
impl Display for SecretKey
impl Display for ByteUnit
Display self
as best as possible. For perfectly custom display output,
consider using ByteUnit::repr()
.
§Example
use ubyte::{ByteUnit, ToByteUnit};
assert_eq!(323.kilobytes().to_string(), "323kB");
assert_eq!(3.megabytes().to_string(), "3MB");
assert_eq!(3.mebibytes().to_string(), "3MiB");
assert_eq!((3.mebibytes() + 140.kilobytes()).to_string(), "3.13MiB");
assert_eq!((3.mebibytes() + 2.mebibytes()).to_string(), "5MiB");
assert_eq!((7.gigabytes() + 58.mebibytes() + 3.kilobytes()).to_string(), "7.06GB");
assert_eq!((7.gibibytes() + 920.mebibytes()).to_string(), "7.90GiB");
assert_eq!(7231.kilobytes().to_string(), "6.90MiB");
assert_eq!(format!("{:.0}", 7.gibibytes() + 920.mebibytes()), "8GiB");
assert_eq!(format!("{:.1}", 7.gibibytes() + 920.mebibytes()), "7.9GiB");
assert_eq!(format!("{:.2}", 7.gibibytes() + 920.mebibytes()), "7.90GiB");
assert_eq!(format!("{:.3}", 7.gibibytes() + 920.mebibytes()), "7.898GiB");
assert_eq!(format!("{:.4}", 7.gibibytes() + 920.mebibytes()), "7.8984GiB");
assert_eq!(format!("{:.4}", 7231.kilobytes()), "6.8960MiB");
assert_eq!(format!("{:.0}", 7231.kilobytes()), "7MiB");
assert_eq!(format!("{:.2}", 999.kilobytes() + 990.bytes()), "976.55KiB");
assert_eq!(format!("{:.0}", 999.kilobytes() + 990.bytes()), "1MB");
assert_eq!(format!("{:04.2}", 999.kilobytes() + 990.bytes()), "0976.55KiB");
assert_eq!(format!("{:02.0}", 999.kilobytes() + 990.bytes()), "01MB");
assert_eq!(format!("{:04.0}", 999.kilobytes() + 990.bytes()), "0001MB");
impl Display for N
impl Display for Empty
impl Display for InvalidOption<'_>
impl Display for rocket::fairing::Kind
impl Display for rocket::form::name::Key
impl Display for rocket::form::name::Name
impl Display for NameBuf<'_>
impl Display for NameView<'_>
impl Display for rocket::form::Error<'_>
impl Display for Errors<'_>
impl Display for Accept
impl Display for ContentType
impl Display for Header<'_>
impl Display for MediaType
impl Display for RawStr
impl Display for RawStrBuf
impl Display for Status
impl Display for Uncased<'_>
impl Display for UncasedStr
impl Display for TryFromUriError
impl Display for Absolute<'_>
impl Display for Asterisk
impl Display for rocket::http::uri::Authority<'_>
impl Display for rocket::http::uri::Error<'_>
impl Display for Host<'_>
impl Display for Origin<'_>
impl Display for Path<'_>
impl Display for Query<'_>
impl Display for Reference<'_>
impl Display for RouteUri<'_>
impl Display for Braced
impl Display for Hyphenated
impl Display for Simple
impl Display for Urn
impl Display for rocket::serde::uuid::Error
impl Display for Uuid
impl Display for rocket::Error
impl Display for rocket::trace::LevelFilter
impl Display for RequestId
trace
only.impl Display for rocket::mtls::Name<'_>
impl Display for ASN1Time
impl Display for KeyUsage
impl Display for NSCertType
impl Display for ReasonCode
impl Display for ReasonFlags
impl Display for X509Version
impl Display for BigInt
impl Display for BigUint
impl Display for ParseBigIntError
impl Display for ASN1DateTime
impl Display for GeneralizedTime
impl Display for Tag
impl Display for UtcTime
impl Display for rocket::mtls::x509::der_parser::asn1_rs::nom::lib::std::alloc::AllocError
impl Display for LayoutError
impl Display for UnorderedKeyError
impl Display for rocket::mtls::x509::der_parser::asn1_rs::nom::lib::std::collections::TryReserveError
impl Display for ParseBoolError
impl Display for Utf8Error
impl Display for FromUtf8Error
impl Display for FromUtf16Error
impl Display for String
impl Display for FromVecWithNulError
impl Display for IntoStringError
impl Display for NulError
impl Display for core::array::TryFromSliceError
impl Display for core::ascii::EscapeDefault
impl Display for BorrowError
impl Display for BorrowMutError
impl Display for CharTryFromError
impl Display for ParseCharError
impl Display for DecodeUtf16Error
impl Display for core::char::EscapeDebug
impl Display for core::char::EscapeDefault
impl Display for core::char::EscapeUnicode
impl Display for ToLowercase
impl Display for ToUppercase
impl Display for TryFromCharError
impl Display for FromBytesUntilNulError
impl Display for FromBytesWithNulError
impl Display for Ipv4Addr
impl Display for Ipv6Addr
Writes an Ipv6Addr, conforming to the canonical style described by RFC 5952.
impl Display for core::net::parser::AddrParseError
impl Display for SocketAddrV4
impl Display for SocketAddrV6
impl Display for core::num::dec2flt::ParseFloatError
impl Display for core::num::error::ParseIntError
impl Display for core::num::error::TryFromIntError
impl Display for core::panic::location::Location<'_>
impl Display for PanicInfo<'_>
impl Display for PanicMessage<'_>
impl Display for TryFromFloatSecsError
impl Display for Backtrace
impl Display for JoinPathsError
impl Display for std::ffi::os_str::Display<'_>
impl Display for WriterPanicked
impl Display for std::io::error::Error
impl Display for PanicHookInfo<'_>
impl Display for std::path::Display<'_>
impl Display for StripPrefixError
impl Display for ExitStatus
impl Display for ExitStatusError
impl Display for std::sync::mpsc::RecvError
impl Display for AccessError
impl Display for SystemTimeError
impl Display for aead::Error
impl Display for allocator_api2::stable::alloc::AllocError
impl Display for aws_lc_rs::error::KeyRejected
impl Display for aws_lc_rs::error::Unspecified
impl Display for bitflags::parser::ParseError
impl Display for block_buffer::Error
impl Display for OverflowError
impl Display for StreamCipherError
impl Display for ObjectIdentifier
impl Display for CookieBuilder<'_>
impl Display for crypto_common::InvalidLength
impl Display for data_encoding::DecodeError
impl Display for SpecificationError
impl Display for deranged::ParseIntError
impl Display for deranged::TryFromIntError
impl Display for MacError
impl Display for InvalidBufferSize
impl Display for InvalidOutputSize
impl Display for figment::error::Error
impl Display for OneOf
impl Display for Profile
impl Display for futures_channel::mpsc::SendError
impl Display for futures_channel::mpsc::TryRecvError
impl Display for Canceled
impl Display for SpawnError
impl Display for Aborted
impl Display for getrandom::error::Error
impl Display for h2::error::Error
impl Display for Reason
impl Display for h3::error::Error
impl Display for InvalidStreamId
impl Display for StreamId
impl Display for hkdf::errors::InvalidLength
impl Display for InvalidPrkLength
impl Display for http::error::Error
impl Display for MaxSizeReached
impl Display for HeaderName
impl Display for InvalidHeaderName
impl Display for InvalidHeaderValue
impl Display for ToStrError
impl Display for InvalidMethod
impl Display for http::method::Method
impl Display for InvalidStatusCode
impl Display for StatusCode
Formats the status code, including the canonical reason.
§Example
assert_eq!(format!("{}", StatusCode::OK), "200 OK");
impl Display for http::uri::authority::Authority
impl Display for PathAndQuery
impl Display for Scheme
impl Display for InvalidUri
impl Display for InvalidUriParts
impl Display for http::uri::Uri
impl Display for InvalidChunkSize
impl Display for HttpDate
impl Display for httpdate::Error
impl Display for hyper::error::Error
impl Display for indexmap::TryReserveError
impl Display for InlineString
impl Display for IntoArrayError
impl Display for NotEqualError
impl Display for OutIsTooSmallError
impl Display for log::ParseLevelError
impl Display for SetLoggerError
impl Display for FromStrError
impl Display for Mime
impl Display for ParseRatioError
impl Display for num_traits::ParseFloatError
impl Display for ring::error::KeyRejected
impl Display for ring::error::Unspecified
impl Display for Errno
impl Display for rustls_pki_types::server_name::AddrParseError
impl Display for InvalidDnsNameError
impl Display for UnsupportedOperationError
impl Display for OtherError
impl Display for s2n_codec::unaligned::TryFromIntError
impl Display for s2n_codec::zerocopy::I16
impl Display for s2n_codec::zerocopy::I32
impl Display for s2n_codec::zerocopy::I64
impl Display for s2n_codec::zerocopy::I128
impl Display for s2n_codec::zerocopy::U16
impl Display for s2n_codec::zerocopy::U32
impl Display for s2n_codec::zerocopy::U64
impl Display for s2n_codec::zerocopy::U128
impl Display for s2n_quic_core::application::error::Error
impl Display for FillError
impl Display for s2n_quic_core::crypto::packet_protection::Error
impl Display for s2n_quic_core::crypto::tls::error::Error
impl Display for FitError
impl Display for EtherType
impl Display for MacAddress
impl Display for Protocol
impl Display for IpV4Address
impl Display for SocketAddressV4
impl Display for IpV6Address
impl Display for SocketAddressV6
impl Display for PacketNumber
impl Display for MtuError
impl Display for Timestamp
impl Display for Code
impl Display for s2n_quic_core::transport::error::Error
impl Display for ValidationError
impl Display for VarInt
impl Display for VarIntError
impl Display for MaxSegmentsError
impl Display for Connect
impl Display for StartError
impl Display for serde::de::value::Error
impl Display for serde_json::error::Error
impl Display for Number
impl Display for RawValue
impl Display for PathPersistError
impl Display for time::date::Date
impl Display for Duration
The format returned by this implementation is not stable and must not be relied upon.
By default this produces an exact, full-precision printout of the duration.
For a concise, rounded printout instead, you can use the .N
format specifier:
let duration = Duration::new(123456, 789011223);
println!("{duration:.3}");
For the purposes of this implementation, a day is exactly 24 hours and a minute is exactly 60 seconds.
impl Display for ComponentRange
impl Display for ConversionRange
impl Display for DifferentVariant
impl Display for InvalidVariant
impl Display for OffsetDateTime
impl Display for PrimitiveDateTime
impl Display for time::time::Time
impl Display for UtcOffset
impl Display for tinyvec::arrayvec::TryFromSliceError
impl Display for tokio_stream::stream_ext::timeout::Elapsed
impl Display for LengthDelimitedCodecError
impl Display for tokio::net::tcp::split_owned::ReuniteError
impl Display for tokio::net::unix::split_owned::ReuniteError
impl Display for TryCurrentError
impl Display for JoinError
impl Display for AcquireError
impl Display for tokio::sync::mutex::TryLockError
impl Display for tokio::sync::oneshot::error::RecvError
impl Display for tokio::sync::watch::error::RecvError
impl Display for tokio::time::error::Elapsed
impl Display for tokio::time::error::Error
impl Display for toml::de::Error
impl Display for Map<String, Value>
impl Display for toml::ser::Error
impl Display for toml_datetime::datetime::Date
impl Display for Datetime
impl Display for DatetimeParseError
impl Display for toml_datetime::datetime::Time
impl Display for Array
impl Display for ArrayOfTables
impl Display for toml_edit::de::Error
impl Display for DocumentMut
impl Display for TomlError
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 InlineTable
impl Display for InternalString
impl Display for toml_edit::key::Key
impl Display for Table
impl Display for SetGlobalDefaultError
impl Display for Field
impl Display for FieldSet
impl Display for tracing_core::metadata::ParseLevelError
impl Display for ParseLevelFilterError
impl Display for tracing_subscriber::filter::directive::ParseError
impl Display for Targets
impl Display for tracing_subscriber::reload::Error
impl Display for TryInitError
impl Display for universal_hash::Error
impl Display for ContextError
impl Display for BStr
impl Display for Bytes
impl Display for Range
impl Display for getrandom::error::Error
impl Display for rand::rngs::adapter::read::ReadError
impl Display for rand::rngs::adapter::read::ReadError
impl Display for rand_core::error::Error
impl Display for rand_core::error::Error
impl Display for Arguments<'_>
impl Display for rocket::mtls::x509::der_parser::asn1_rs::nom::lib::std::fmt::Error
impl Display for ConnectionError
impl Display for ReadError
impl Display for SendStreamError
impl Display for dyn Value
impl<'a> Display for rocket::serde::json::Error<'a>
json
only.impl<'a> Display for GeneralName<'a>
impl<'a> Display for s2n_quic_core::event::generated::api::SocketAddress<'a>
impl<'a> Display for Unexpected<'a>
impl<'a> Display for Oid<'a>
impl<'a> Display for X509Name<'a>
impl<'a> Display for EscapeAscii<'a>
impl<'a> Display for rocket::mtls::x509::der_parser::asn1_rs::nom::lib::std::str::EscapeDebug<'a>
impl<'a> Display for rocket::mtls::x509::der_parser::asn1_rs::nom::lib::std::str::EscapeDefault<'a>
impl<'a> Display for rocket::mtls::x509::der_parser::asn1_rs::nom::lib::std::str::EscapeUnicode<'a>
impl<'a> Display for mime::Name<'a>
impl<'a> Display for PercentEncode<'a>
impl<'a> Display for ValueSet<'a>
impl<'a> Display for dyn Expected + 'a
impl<'a, 'c> Display for cookie::Display<'a, 'c>where
'c: 'a,
impl<'a, 'e, E> Display for Base64Display<'a, 'e, E>where
E: Engine,
impl<'a, D> Display for Program<'a, D>where
D: Dialect,
impl<'a, E> Display for DecodeStringError<'a, E>where
E: RmpReadErr,
impl<'a, K, V> Display for rocket::mtls::x509::der_parser::asn1_rs::nom::lib::std::collections::hash_map::OccupiedError<'a, K, V>
impl<'a, K, V, A> Display for rocket::mtls::x509::der_parser::asn1_rs::nom::lib::std::collections::btree_map::OccupiedError<'a, K, V, A>
impl<'a, K, V, S, A> Display for hashbrown::map::OccupiedError<'a, K, V, S, A>
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::mutex::MutexGuard<'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::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 SpinMutexGuard<'a, T>
impl<'a, T> Display for spin::mutex::MutexGuard<'a, T>
impl<'a, T> Display for tokio::sync::mutex::MappedMutexGuard<'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, T> Display for RwLockMappedWriteGuard<'a, T>
impl<'c> Display for Cookie<'c>
impl<'k> Display for KeyMut<'k>
impl<'rwlock, T> Display for spin::rwlock::RwLockReadGuard<'rwlock, T>
impl<'rwlock, T, R> Display for RwLockUpgradableGuard<'rwlock, T, R>
impl<'rwlock, T, R> Display for spin::rwlock::RwLockWriteGuard<'rwlock, T, R>
impl<'s, T> Display for SliceVec<'s, T>where
T: Display,
impl<A> Display for TinyVec<A>
impl<A> Display for ArrayVec<A>
impl<B> Display for Cow<'_, B>
impl<C, E> Display for pear::error::ParseError<C, E>
impl<D> Display for Instruction<D>where
D: Dialect,
impl<E> Display for Err<E>where
E: Debug,
impl<E> Display for NumValueReadError<E>where
E: RmpReadErr,
impl<E> Display for ValueWriteError<E>where
E: RmpWriteErr,
impl<E> Display for s2n_quic_core::buffer::error::Error<E>where
E: Display,
impl<E> Display for ErrMode<E>where
E: Debug,
impl<E> Display for Report<E>where
E: Error,
impl<E> Display for FormattedFields<E>where
E: ?Sized,
impl<F> Display for PersistError<F>
impl<F> Display for FromFn<F>
impl<I> Display for rocket::mtls::x509::der_parser::asn1_rs::nom::error::Error<I>where
I: Display,
The Display implementation allows the std::error::Error implementation
impl<I> Display for VerboseError<I>where
I: Display,
impl<I> Display for InputError<I>
The Display implementation allows the std::error::Error
implementation