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.
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
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, }));
Implementors
impl Display for AccountsSaveError
impl Display for InvalidScopedName
impl Display for KeyError
impl Display for Kind
impl Display for LoadError
impl Display for State
impl Display for MgmtError
impl Display for ApiPieceOpError
impl Display for Fatal
impl Display for Inapplicable
impl Display for InternalError
impl Display for PieceOpErrorPartiallyProcessed
impl Display for Infallible
impl Display for ZipError
impl Display for RecvTimeoutError
impl Display for TryRecvError
impl Display for VersionError
impl Display for SVGProcessingError
impl Display for LibraryLoadError
impl Display for LibraryLoadMFIncompat
impl Display for SubstErrorKind
impl Display for LinkKind
impl Display for SpecError
impl Display for SVGSizeError
impl Display for SVGWidthOrHeight
impl Display for RoundingError
impl Display for otter::prelude::chrono::Weekday
impl Display for Tz
impl Display for otter::prelude::ErrorKind
impl Display for otter::prelude::IpAddr
impl Display for PacketFrameReadError
impl Display for PacketFrameWriteError
impl Display for SocketAddr
impl Display for VarError
impl Display for FlexiLoggerError
impl Display for Level
impl Display for LevelFilter
impl Display for Errno
impl Display for Signal
impl Display for InetAddr
impl Display for otter::prelude::nix::sys::socket::IpAddr
impl Display for SockAddr
impl Display for PwdError
impl Display for BernoulliError
impl Display for WeightedError
impl Display for otter::prelude::rmp_serde::decode::Error
impl Display for otter::prelude::rmp_serde::encode::Error
impl Display for otter::prelude::toml::Value
impl Display for otter::prelude::toml::ser::Error
impl Display for Offset
impl Display for otter::prelude::toml_de::Error
impl Display for otter::prelude::otter_base::crates::serde_json::Value
impl Display for LogicError
impl Display for RangeImpossible
impl Display for Void
impl Display for time::ParseError
impl Display for DecodeError
impl Display for base64ct::errors::Error
impl Display for bzip2::mem::Error
impl Display for ImageError
impl Display for ImageFormatHint
impl Display for image::flat::Error
impl Display for Curve
impl Display for OpenSSHKeyError
impl Display for otter_support::slotmap_slot_idx::Error
impl Display for password_hash::errors::Error
impl Display for InvalidValue
impl Display for Algorithm
impl Display for regex::error::Error
impl Display for strum::ParseError
impl Display for LogicOperator
impl Display for MathOperator
impl Display for url::parser::ParseError
impl Display for SyntaxViolation
impl Display for xmlparser::error::Error
impl Display for StreamError
impl Display for CompressionMethod
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 AuthKeysManipError
impl Display for Comment
impl Display for Fingerprint
impl Display for otter::accounts::sshkeys::Id
impl Display for KeySpec
impl Display for MgmtKeyReport
impl Display for Nonce
impl Display for PubData
impl Display for AccountName
impl Display for AccountNotFound
impl Display for AssetUrlToken
impl Display for BadAssetUrlToken
impl Display for Hash
impl Display for otter::bundles::Id
impl Display for Index
impl Display for NotBundle
impl Display for ZipIndex
impl Display for GameBeingDestroyed
impl Display for InternalLogicError
impl Display for TokenDeliveryError
impl Display for UnsupportedColourSpec
impl Display for FastSplitId
impl Display for Generation
impl Display for GoodItemName
impl Display for PlayerId
impl Display for VisiblePieceId
impl Display for ClientId
impl Display for InstanceName
impl Display for PlayerNotFound
impl Display for OccId
impl Display for RecvError
impl Display for NonZeroUsize
impl Display for otter::imports::Regex
impl Display for Url
Display the serialization of this URL.
impl Display for AccessError
impl Display for Unsupported
impl Display for Version
impl Display for ItemEnquiryData
impl Display for LibraryEnquiryData
impl Display for SubstError
impl Display for AbbrevPresentationLayout
impl Display for InvalidAbbrevPresentationLayout
impl Display for UpdateId
impl Display for AnyhowDisplay<'_>
impl Display for FutureInstantOutOfRange
impl Display for otter::prelude::anyhow::Error
impl Display for AuthorisationError
impl Display for otter::prelude::chrono::Duration
impl Display for FixedOffset
impl Display for NaiveDate
The Display
output of the naive date d
is the same as
d.format("%Y-%m-%d")
.
The string printed can be readily parsed via the parse
method on str
.
Example
use chrono::NaiveDate;
assert_eq!(format!("{}", NaiveDate::from_ymd(2015, 9, 5)), "2015-09-05");
assert_eq!(format!("{}", NaiveDate::from_ymd( 0, 1, 1)), "0000-01-01");
assert_eq!(format!("{}", NaiveDate::from_ymd(9999, 12, 31)), "9999-12-31");
ISO 8601 requires an explicit sign for years before 1 BCE or after 9999 CE.
assert_eq!(format!("{}", NaiveDate::from_ymd( -1, 1, 1)), "-0001-01-01");
assert_eq!(format!("{}", NaiveDate::from_ymd(10000, 12, 31)), "+10000-12-31");
impl Display for NaiveDateTime
The Display
output of the naive date and time dt
is the same as
dt.format("%Y-%m-%d %H:%M:%S%.f")
.
It should be noted that, for leap seconds not on the minute boundary, it may print a representation not distinguishable from non-leap seconds. This doesn’t matter in practice, since such leap seconds never happened. (By the time of the first leap second on 1972-06-30, every time zone offset around the world has standardized to the 5-minute alignment.)
Example
use chrono::NaiveDate;
let dt = NaiveDate::from_ymd(2016, 11, 15).and_hms(7, 39, 24);
assert_eq!(format!("{}", dt), "2016-11-15 07:39:24");
Leap seconds may also be used.
let dt = NaiveDate::from_ymd(2015, 6, 30).and_hms_milli(23, 59, 59, 1_500);
assert_eq!(format!("{}", dt), "2015-06-30 23:59:60.500");
impl Display for NaiveTime
The Display
output of the naive time t
is the same as
t.format("%H:%M:%S%.f")
.
The string printed can be readily parsed via the parse
method on str
.
It should be noted that, for leap seconds not on the minute boundary, it may print a representation not distinguishable from non-leap seconds. This doesn’t matter in practice, since such leap seconds never happened. (By the time of the first leap second on 1972-06-30, every time zone offset around the world has standardized to the 5-minute alignment.)
Example
use chrono::NaiveTime;
assert_eq!(format!("{}", NaiveTime::from_hms(23, 56, 4)), "23:56:04");
assert_eq!(format!("{}", NaiveTime::from_hms_milli(23, 56, 4, 12)), "23:56:04.012");
assert_eq!(format!("{}", NaiveTime::from_hms_micro(23, 56, 4, 1234)), "23:56:04.001234");
assert_eq!(format!("{}", NaiveTime::from_hms_nano(23, 56, 4, 123456)), "23:56:04.000123456");
Leap seconds may also be used.
assert_eq!(format!("{}", NaiveTime::from_hms_milli(6, 59, 59, 1_500)), "06:59:60.500");
impl Display for otter::prelude::chrono::ParseError
impl Display for Utc
impl Display for InvalidBufferSize
impl Display for otter::prelude::digest::InvalidLength
impl Display for otter::prelude::digest::InvalidOutputSize
impl Display for MacError
impl Display for JoinPathsError
impl Display for otter::prelude::fmt::Error
impl Display for otter::prelude::io::Error
impl Display for WriterPanicked
impl Display for ParseLevelError
impl Display for SetLoggerError
impl Display for ClearEnvError
impl Display for AlgAddr
impl Display for otter::prelude::nix::sys::socket::Ipv4Addr
impl Display for otter::prelude::nix::sys::socket::Ipv6Addr
impl Display for LinkAddr
impl Display for NetlinkAddr
impl Display for SockaddrIn6
impl Display for SockaddrIn
impl Display for UnixAddr
impl Display for VsockAddr
impl Display for TimeVal
impl Display for ClockId
impl Display for ReadError
impl Display for otter::prelude::rand::Error
impl Display for InvalidFakeTime
impl Display for otter::prelude::Ipv4Addr
impl Display for otter::prelude::Ipv6Addr
Write an Ipv6Addr, conforming to the canonical style described by RFC 5952.
impl Display for RngIsReal
impl Display for TimeIsReal
impl Display for TimeSpec
impl Display for Timezone
impl Display for Uid
impl Display for FromFloatSecsError
impl Display for SystemTimeError
impl Display for otter::prelude::toml::de::Error
impl Display for otter::prelude::toml::value::Date
impl Display for Datetime
impl Display for DatetimeParseError
impl Display for otter::prelude::toml::value::Time
impl Display for Gid
impl Display for Pid
impl Display for otter::prelude::otter_base::crates::serde::de::value::Error
impl Display for otter::prelude::otter_base::crates::serde_json::Error
impl Display for Number
impl Display for CoordinateOverflow
impl Display for PosCFromIteratorError
impl Display for ParseBoolError
impl Display for otter::prelude::otter_base::imports::str::Utf8Error
impl Display for LimbVal
impl Display for Overflow
impl Display for otter::prelude::otter_base::zcoord::ParseError
impl Display for TotallyUnboundedRange
impl Display for ZCoord
impl Display for TryReserveError
impl Display for FromVecWithNulError
impl Display for IntoStringError
impl Display for NulError
impl Display for alloc::string::FromUtf8Error
impl Display for FromUtf16Error
impl Display for String
impl Display for LayoutError
impl Display for AllocError
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 core::num::dec2flt::ParseFloatError
impl Display for ParseIntError
impl Display for NonZeroI8
impl Display for NonZeroI16
impl Display for NonZeroI32
impl Display for NonZeroI64
impl Display for NonZeroI128
impl Display for NonZeroIsize
impl Display for NonZeroU8
impl Display for NonZeroU16
impl Display for NonZeroU32
impl Display for NonZeroU64
impl Display for NonZeroU128
impl Display for Utf8Lossy
impl Display for std::backtrace::Backtrace
impl Display for Report<Box<dyn Error + 'static, Global>>
impl Display for SocketAddrV4
impl Display for SocketAddrV6
impl Display for AddrParseError
impl Display for StripPrefixError
impl Display for ExitStatus
impl Display for ExitStatusError
impl Display for OutOfRangeError
impl Display for SteadyTime
impl Display for InvalidEncodingError
impl Display for InvalidLengthError
impl Display for env_logger::fmt::humantime::imp::Timestamp
impl Display for erased_serde::error::Error
impl Display for CompressError
impl Display for DecompressError
impl Display for getrandom::error::Error
impl Display for glob::GlobError
impl Display for Pattern
Show the original glob pattern.
impl Display for PatternError
impl Display for image::error::DecodingError
impl Display for image::error::EncodingError
impl Display for LimitError
impl Display for image::error::ParameterError
impl Display for UnsupportedError
impl Display for BigInt
impl Display for BigUint
impl Display for ParseBigIntError
impl Display for ParseRatioError
impl Display for num_traits::ParseFloatError
impl Display for PublicKey
impl Display for FloatIsNan
impl Display for Broken
impl Display for SenderError
impl Display for Output
impl Display for ParamsString
impl Display for regex::re_bytes::Regex
impl Display for PathPersistError
impl Display for PersistError
impl Display for tera::errors::Error
impl Display for UnixSocketAddr
impl Display for TextPos
impl Display for InvalidPassword
impl Display for TryFromIntError
impl Display for SockaddrStorage
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 BStr
impl Display for BString
impl Display for Backtrace
impl Display for BlendOp
impl Display for BytesReadError
impl Display for CaseFoldError
impl Display for CheckedCastError
impl Display for CollectionAllocErr
impl Display for ComponentRange
impl Display for ConversionRange
impl Display for Date
impl Display for DecodingError
impl Display for DifferentVariant
impl Display for DisposeOp
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!("{:.3}", duration);
For the purposes of this implementation, a day is exactly 24 hours and a minute is exactly 60 seconds.
impl Display for Duration
impl Display for DwAccess
impl Display for DwAddr
impl Display for DwAt
impl Display for DwAte
impl Display for DwCc
impl Display for DwCfa
impl Display for DwChildren
impl Display for DwDefaulted
impl Display for DwDs
impl Display for DwDsc
impl Display for DwEhPe
impl Display for DwEnd
impl Display for DwForm
impl Display for DwId
impl Display for DwIdx
impl Display for DwInl
impl Display for DwLang
impl Display for DwLle
impl Display for DwLnct
impl Display for DwLne
impl Display for DwLns
impl Display for DwMacro
impl Display for DwOp
impl Display for DwOrd
impl Display for DwRle
impl Display for DwSect
impl Display for DwSectV2
impl Display for DwTag
impl Display for DwUt
impl Display for DwVirtuality
impl Display for DwVis
impl Display for EncodingError
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for Error
impl Display for ErrorKind
impl Display for ErrorKind
impl Display for ErrorKind
impl Display for Errors
impl Display for FileTime
impl Display for Format
impl Display for FormattedDuration
impl Display for FromUtf8Error
impl Display for Glob
impl Display for GlobError
impl Display for GraphemeClusterBreak
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
.