Trait frame_support::dispatch::fmt::Display
1.0.0 · source · 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.
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§
sourcefn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
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, }));
Implementors§
impl Display for base16ct::error::Error
impl Display for DecodeError
impl Display for bincode::error::ErrorKind
impl Display for bip39::error::ErrorKind
impl Display for MnemonicType
impl Display for byte_slice_cast::Error
impl Display for RoundingError
impl Display for Weekday
impl Display for const_oid::error::Error
impl Display for cpp_demangle::error::Error
impl Display for Reloc
impl Display for DataValue
impl Display for DataValueCastFailure
impl Display for AtomicRmwOp
impl Display for FloatCC
impl Display for IntCC
impl Display for AnyEntity
impl Display for ArgumentPurpose
impl Display for UserFuncName
impl Display for GlobalValueData
impl Display for Opcode
impl Display for KnownSymbol
impl Display for LibCall
impl Display for ExpandedProgramPoint
impl Display for StackSlotKind
impl Display for cranelift_codegen::ir::trapcode::TrapCode
impl Display for CallConv
impl Display for LookupError
impl Display for RegisterMappingError
impl Display for CodegenError
impl Display for LibcallCallConv
impl Display for OptLevel
impl Display for ProbestackStrategy
impl Display for SetError
impl Display for TlsModel
impl Display for crossbeam_channel::err::RecvTimeoutError
impl Display for crossbeam_channel::err::TryRecvError
impl Display for der::error::ErrorKind
impl Display for Class
impl Display for Tag
impl Display for TagMode
impl Display for ed25519_zebra::error::Error
impl Display for gimli::read::Error
impl Display for gimli::read::Error
impl Display for ConvertError
impl Display for gimli::write::Error
impl Display for hex::error::FromHexError
impl Display for humantime::date::Error
impl Display for humantime::duration::Error
impl Display for GetTimezoneError
impl Display for libsecp256k1_core::error::Error
impl Display for log::Level
impl Display for log::LevelFilter
impl Display for num_format::error_kind::ErrorKind
impl Display for parity_wasm::elements::Error
impl Display for Instruction
impl Display for parity_wasm::elements::types::ValueType
impl Display for pkcs8::error::Error
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 OperandConstraint
impl Display for RegAllocError
impl Display for regex::error::Error
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 regex_syntax::ast::ErrorKind
impl Display for regex_syntax::error::Error
impl Display for regex_syntax::hir::ErrorKind
impl Display for rustc_hex::FromHexError
impl Display for MultiSignatureStage
impl Display for SignatureError
impl Display for sec1::error::Error
impl Display for secp256k1::Error
impl Display for serde_json::value::Value
impl Display for CollectionAllocErr
impl Display for ApiError
impl Display for PublicError
impl Display for sp_inherents::Error
impl Display for sp_keystore::Error
impl Display for MultiSigner
impl Display for RuntimeString
impl Display for ExecutionError
impl Display for sp_version::embed::Error
impl Display for spki::error::Error
impl Display for Ss58AddressFormatRegistry
impl Display for target_lexicon::parse_error::ParseError
impl Display for Aarch64Architecture
impl Display for Architecture
impl Display for ArmArchitecture
impl Display for BinaryFormat
impl Display for Environment
impl Display for Mips32Architecture
impl Display for Mips64Architecture
impl Display for OperatingSystem
impl Display for Riscv32Architecture
impl Display for Riscv64Architecture
impl Display for Vendor
impl Display for X86_32Architecture
impl Display for time::ParseError
impl Display for Offset
impl Display for toml::ser::Error
impl Display for toml::value::Value
impl Display for FromDecStrErr
impl Display for wasmi::Error
impl Display for wasmi_core::trap::Trap
impl Display for wasmi_core::trap::TrapCode
impl Display for UntypedError
impl Display for wasmi_core::value::Value
impl Display for wasmi_core::value::ValueType
impl Display for wasmtime::trap::TrapCode
impl Display for ValType
impl Display for CompileError
impl Display for FlagValue
impl Display for SetupError
impl Display for InstantiationError
impl Display for WasmType
impl Display for WasmError
impl Display for TransactionValidityError
impl Display for StateVersion
impl Display for AsciiChar
impl Display for Infallible
impl Display for IpAddr
impl Display for SocketAddr
impl Display for VarError
impl Display for std::io::error::ErrorKind
impl Display for std::sync::mpsc::RecvTimeoutError
impl Display for std::sync::mpsc::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 aho_corasick::error::Error
impl Display for Infix
impl Display for Prefix
impl Display for Suffix
impl Display for anyhow::Error
impl Display for base16ct::display::HexDisplay<'_>
impl Display for Mnemonic
impl Display for block_buffer::Error
impl Display for AllocErr
impl Display for chrono::format::ParseError
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_opt(2015, 9, 5).unwrap()), "2015-09-05");
assert_eq!(format!("{}", NaiveDate::from_ymd_opt( 0, 1, 1).unwrap()), "0000-01-01");
assert_eq!(format!("{}", NaiveDate::from_ymd_opt(9999, 12, 31).unwrap()), "9999-12-31");
ISO 8601 requires an explicit sign for years before 1 BCE or after 9999 CE.
assert_eq!(format!("{}", NaiveDate::from_ymd_opt( -1, 1, 1).unwrap()), "-0001-01-01");
assert_eq!(format!("{}", NaiveDate::from_ymd_opt(10000, 12, 31).unwrap()), "+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_opt(2016, 11, 15).unwrap().and_hms_opt(7, 39, 24).unwrap();
assert_eq!(format!("{}", dt), "2016-11-15 07:39:24");
Leap seconds may also be used.
let dt = NaiveDate::from_ymd_opt(2015, 6, 30).unwrap().and_hms_milli_opt(23, 59, 59, 1_500).unwrap();
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_opt(23, 56, 4).unwrap()), "23:56:04");
assert_eq!(format!("{}", NaiveTime::from_hms_milli_opt(23, 56, 4, 12).unwrap()), "23:56:04.012");
assert_eq!(format!("{}", NaiveTime::from_hms_micro_opt(23, 56, 4, 1234).unwrap()), "23:56:04.001234");
assert_eq!(format!("{}", NaiveTime::from_hms_nano_opt(23, 56, 4, 123456).unwrap()), "23:56:04.000123456");
Leap seconds may also be used.
assert_eq!(format!("{}", NaiveTime::from_hms_milli_opt(6, 59, 59, 1_500).unwrap()), "06:59:60.500");
impl Display for FixedOffset
impl Display for Utc
impl Display for ParseWeekdayError
impl Display for ObjectIdentifier
impl Display for ConstantData
impl Display for Block
impl Display for Constant
impl Display for DynamicStackSlot
impl Display for DynamicType
impl Display for FuncRef
impl Display for GlobalValue
impl Display for Heap
impl Display for Immediate
impl Display for Inst
impl Display for JumpTable
impl Display for SigRef
impl Display for StackSlot
impl Display for Table
impl Display for UserExternalNameRef
impl Display for cranelift_codegen::ir::entities::Value
impl Display for AbiParam
impl Display for cranelift_codegen::ir::extfunc::Signature
impl Display for UserExternalName
impl Display for Function
impl Display for HeapData
impl Display for Ieee32
impl Display for Ieee64
impl Display for Imm64
impl Display for Offset32
impl Display for Uimm32
impl Display for Uimm64
impl Display for VariableArgs
impl Display for JumpTableData
impl Display for MemFlags
impl Display for ProgramPoint
impl Display for RelSourceLoc
impl Display for SourceLoc
impl Display for DynamicStackSlotData
impl Display for StackSlotData
impl Display for ValueLabel
impl Display for TableData
impl Display for Type
impl Display for Loop
impl Display for Flags
impl Display for cranelift_codegen::settings::Value
impl Display for PassTimes
impl Display for VerifierError
impl Display for VerifierErrors
impl Display for crossbeam_channel::err::RecvError
impl Display for SelectTimeoutError
impl Display for TrySelectError
impl Display for Limb
impl Display for InvalidLength
impl Display for der::datetime::DateTime
impl Display for der::error::Error
impl Display for Length
impl Display for TagNumber
impl Display for digest::errors::InvalidOutputSize
impl Display for digest::errors::InvalidOutputSize
impl Display for digest::mac::MacError
impl Display for InvalidBufferSize
impl Display for digest::InvalidOutputSize
impl Display for ed25519::Signature
impl Display for elliptic_curve::error::Error
impl Display for env_logger::fmt::humantime::imp::Timestamp
impl Display for futures_channel::mpsc::SendError
impl Display for futures_channel::mpsc::TryRecvError
impl Display for Canceled
impl Display for EnterError
impl Display for SpawnError
impl Display for Aborted
impl Display for getrandom::error::Error
impl Display for getrandom::error::Error
impl Display for gimli::constants::DwAccess
impl Display for gimli::constants::DwAccess
impl Display for gimli::constants::DwAddr
impl Display for gimli::constants::DwAddr
impl Display for gimli::constants::DwAt
impl Display for gimli::constants::DwAt
impl Display for gimli::constants::DwAte
impl Display for gimli::constants::DwAte
impl Display for gimli::constants::DwCc
impl Display for gimli::constants::DwCc
impl Display for gimli::constants::DwCfa
impl Display for gimli::constants::DwCfa
impl Display for gimli::constants::DwChildren
impl Display for gimli::constants::DwChildren
impl Display for gimli::constants::DwDefaulted
impl Display for gimli::constants::DwDefaulted
impl Display for gimli::constants::DwDs
impl Display for gimli::constants::DwDs
impl Display for gimli::constants::DwDsc
impl Display for gimli::constants::DwDsc
impl Display for gimli::constants::DwEhPe
impl Display for gimli::constants::DwEhPe
impl Display for gimli::constants::DwEnd
impl Display for gimli::constants::DwEnd
impl Display for gimli::constants::DwForm
impl Display for gimli::constants::DwForm
impl Display for gimli::constants::DwId
impl Display for gimli::constants::DwId
impl Display for gimli::constants::DwIdx
impl Display for gimli::constants::DwIdx
impl Display for gimli::constants::DwInl
impl Display for gimli::constants::DwInl
impl Display for gimli::constants::DwLang
impl Display for gimli::constants::DwLang
impl Display for gimli::constants::DwLle
impl Display for gimli::constants::DwLle
impl Display for gimli::constants::DwLnct
impl Display for gimli::constants::DwLnct
impl Display for gimli::constants::DwLne
impl Display for gimli::constants::DwLne
impl Display for gimli::constants::DwLns
impl Display for gimli::constants::DwLns
impl Display for gimli::constants::DwMacro
impl Display for gimli::constants::DwMacro
impl Display for gimli::constants::DwOp
impl Display for gimli::constants::DwOp
impl Display for gimli::constants::DwOrd
impl Display for gimli::constants::DwOrd
impl Display for gimli::constants::DwRle
impl Display for gimli::constants::DwRle
impl Display for gimli::constants::DwSect
impl Display for gimli::constants::DwSect
impl Display for gimli::constants::DwSectV2
impl Display for gimli::constants::DwSectV2
impl Display for gimli::constants::DwTag
impl Display for gimli::constants::DwTag
impl Display for gimli::constants::DwUt
impl Display for gimli::constants::DwUt
impl Display for gimli::constants::DwVirtuality
impl Display for gimli::constants::DwVirtuality
impl Display for gimli::constants::DwVis
impl Display for gimli::constants::DwVis
impl Display for Rfc3339Timestamp
impl Display for FormattedDuration
impl Display for humantime::wrapper::Duration
impl Display for humantime::wrapper::Timestamp
impl Display for log::ParseLevelError
impl Display for SetLoggerError
impl Display for BigInt
impl Display for BigUint
impl Display for ParseBigIntError
impl Display for Buffer
impl Display for num_format::error::Error
impl Display for ParseRatioError
impl Display for num_traits::ParseFloatError
impl Display for object::read::Error
impl Display for object::read::Error
impl Display for object::write::Error
impl Display for parity_scale_codec::error::Error
impl Display for H128
impl Display for H160
impl Display for H256
impl Display for H384
impl Display for H512
impl Display for H768
impl Display for U128
impl Display for U256
impl Display for U512
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 ThreadPoolBuildError
impl Display for Allocation
impl Display for Operand
impl Display for PReg
impl Display for SpillSlot
impl Display for VReg
impl Display for regex::re_bytes::Regex
impl Display for regex::re_unicode::Regex
impl Display for regex_automata::error::Error
impl Display for regex_syntax::ast::Error
impl Display for regex_syntax::hir::Error
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 CaseFoldError
impl Display for UnicodeWordError
impl Display for rustix::backend::io::errno::Errno
impl Display for rustix::backend::io::errno::Errno
impl Display for Path<PortableForm>
impl Display for SerializedSignature
impl Display for secp256k1::ecdsa::Signature
impl Display for InvalidParityValue
impl Display for PublicKey
impl Display for XOnlyPublicKey
impl Display for secp256k1::scalar::OutOfRangeError
impl Display for secp256k1::schnorr::Signature
impl Display for Message
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 signature::error::Error
impl Display for sp_application_crypto::ecdsa::app::Public
impl Display for sp_application_crypto::ed25519::app::Public
impl Display for sp_application_crypto::sr25519::app::Public
impl Display for FixedI64
impl Display for FixedI128
impl Display for FixedU64
impl Display for FixedU128
impl Display for AccountId32
impl Display for CryptoTypePublicPair
impl Display for sp_core::ecdsa::Public
impl Display for sp_core::ed25519::Public
impl Display for sp_core::sr25519::Public
impl Display for CodeNotFound
impl Display for RuntimeVersion
impl Display for Ss58AddressFormat
Display the name of the address format (not the description).
impl Display for ss58_registry::error::ParseError
impl Display for TokenAmount
impl Display for Triple
impl Display for ColorChoiceParseError
impl Display for ParseColorError
impl Display for time::duration::Duration
impl Display for time::duration::OutOfRangeError
impl Display for SteadyTime
impl Display for tinyvec::arrayvec::TryFromSliceError
impl Display for toml::datetime::Date
impl Display for Datetime
impl Display for DatetimeParseError
impl Display for Time
impl Display for toml::de::Error
impl Display for SetGlobalDefaultError
impl Display for Field
impl Display for FieldSet
impl Display for tracing_core::metadata::Level
impl Display for tracing_core::metadata::LevelFilter
impl Display for tracing_core::metadata::ParseLevelError
impl Display for ParseLevelFilterError
impl Display for tracing_subscriber::filter::directive::ParseError
impl Display for Directive
impl Display for BadName
impl Display for EnvFilter
impl Display for FromEnvError
impl Display for tracing_subscriber::reload::Error
impl Display for TryInitError
impl Display for uint::uint::FromHexError
impl Display for FromStrRadixErr
impl Display for wasmi_validation::stack::Error
impl Display for wasmi_validation::Error
impl Display for BinaryReaderError
impl Display for MemoryAccessError
impl Display for wasmtime::trap::Trap
impl Display for LinkError
impl Display for NullPtrError
impl Display for Weight
impl Display for TryReserveError
impl Display for FromVecWithNulError
impl Display for IntoStringError
impl Display for NulError
impl Display for 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 Ipv4Addr
impl Display for Ipv6Addr
Write an Ipv6Addr, conforming to the canonical style described by RFC 5952.