Trait sn0int::fmt::Display 1.0.0[−][src]
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, }));
Implementations on Foreign Types
Write an Ipv6Addr, conforming to the canonical style described by RFC 5952.
impl<'a, T, DB> Display for DebugQuery<'a, T, DB> where
T: QueryFragment<DB>,
DB: Backend,
<DB as Backend>::QueryBuilder: Default,
impl<'a, T, DB> Display for DebugQuery<'a, T, DB> where
T: QueryFragment<DB>,
DB: Backend,
<DB as Backend>::QueryBuilder: Default,
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");
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");
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<'a> Display for MigrationFileName<'a>
impl<'a> Display for MigrationFileName<'a>
impl<R, Offset> Display for LineInstruction<R, Offset> where
Offset: ReaderOffset,
R: Reader<Offset = Offset>,
impl<R, Offset> Display for LineInstruction<R, Offset> where
Offset: ReaderOffset,
R: Reader<Offset = Offset>,
Formats the status code, including the canonical reason.
Example
assert_eq!(format!("{}", StatusCode::OK), "200 OK");
impl<S> Display for TcpClientStream<S> where
S: AsyncRead + AsyncWrite + Send,
impl<S> Display for TcpClientStream<S> where
S: AsyncRead + AsyncWrite + Send,
impl Display for Label
impl Display for Label
Display the serialization of this URL.
The Display implementation allows the std::error::Error implementation
The Display implementation allows the std::error::Error implementation
impl<O, T> Display for BitVec<O, T> where
T: BitStore,
O: BitOrder,
impl<O, T> Display for BitVec<O, T> where
T: BitStore,
O: BitOrder,
impl<R> Display for BitMask<R> where
R: BitRegister,
impl<R> Display for BitMask<R> where
R: BitRegister,
impl<R> Display for BitIdx<R> where
R: BitRegister,
impl<R> Display for BitIdx<R> where
R: BitRegister,
impl<R> Display for BitPos<R> where
R: BitRegister,
impl<R> Display for BitPos<R> where
R: BitRegister,
impl<R> Display for BitTail<R> where
R: BitRegister,
impl<R> Display for BitTail<R> where
R: BitRegister,
impl<R> Display for BitSel<R> where
R: BitRegister,
impl<R> Display for BitSel<R> where
R: BitRegister,
impl<O, T> Display for BitBox<O, T> where
T: BitStore,
O: BitOrder,
impl<O, T> Display for BitBox<O, T> where
T: BitStore,
O: BitOrder,
impl<O, T> Display for BitSlice<O, T> where
T: BitStore,
O: BitOrder,
impl<O, T> Display for BitSlice<O, T> where
T: BitStore,
O: BitOrder,
impl<O, V> Display for BitArray<O, V> where
V: BitView,
O: BitOrder,
impl<O, V> Display for BitArray<O, V> where
V: BitView,
O: BitOrder,
impl Display for InvalidRectCoordinatesError
impl Display for InvalidRectCoordinatesError
impl Display for TiffUnsupportedError
impl Display for TiffUnsupportedError
impl<A> Display for Tendril<UTF8, A> where
A: Atomicity,
impl<A> Display for Tendril<UTF8, A> where
A: Atomicity,
impl<'a> Display for BufReadDecoderError<'a>
impl<'a> Display for BufReadDecoderError<'a>
impl<Static> Display for Atom<Static> where
Static: StaticAtomSet,
impl<Static> Display for Atom<Static> where
Static: StaticAtomSet,
impl<'a> Display for CowRcStr<'a>
impl<'a> Display for CowRcStr<'a>
Display a JSON value as a string.
let json = json!({ "city": "London", "street": "10 Downing Street" });
// Compact format:
//
// {"city":"London","street":"10 Downing Street"}
let compact = format!("{}", json);
assert_eq!(compact,
"{\"city\":\"London\",\"street\":\"10 Downing Street\"}");
// Pretty format:
//
// {
// "city": "London",
// "street": "10 Downing Street"
// }
let pretty = format!("{:#}", json);
assert_eq!(pretty,
"{\n \"city\": \"London\",\n \"street\": \"10 Downing Street\"\n}");
impl Display for TopicFilterError
impl Display for TopicFilterError
impl Display for PacketTypeError
impl Display for PacketTypeError
impl Display for FixedHeaderError
impl Display for FixedHeaderError
impl Display for VariablePacketError
impl Display for VariablePacketError
impl Display for TopicNameDecodeError
impl Display for TopicNameDecodeError
impl<P> Display for PacketError<P> where
P: DecodablePacket,
impl<P> Display for PacketError<P> where
P: DecodablePacket,
impl Display for VariableHeaderError
impl Display for VariableHeaderError
impl Display for ConnectPacketError
impl Display for ConnectPacketError
impl Display for TopicNameError
impl Display for TopicNameError
impl Display for SubscribePacketError
impl Display for SubscribePacketError
impl Display for SubackPacketError
impl Display for SubackPacketError
impl Display for UnsubscribePacketError
impl Display for UnsubscribePacketError
impl Display for TopicFilterDecodeError
impl Display for TopicFilterDecodeError
impl Display for Ast
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 Hir
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
.
Formats the status code, including the canonical reason.
Example
assert_eq!(format!("{}", StatusCode::OK), "200 OK");
impl<Role> Display for HandshakeError<Role> where
Role: HandshakeRole,
impl<Role> Display for HandshakeError<Role> where
Role: HandshakeRole,
impl Display for ProtocolError
impl Display for ProtocolError
impl Display for CapacityError
impl Display for CapacityError
impl<'a, 'b> Display for ReprDisplay<'a, 'b> where
'b: 'a,
impl<'a, 'b> Display for ReprDisplay<'a, 'b> where
'b: 'a,
impl Display for Rational
impl Display for Rational
impl Display for SRational
impl Display for SRational
Show the original glob pattern.