Trait wyz::fmt::FmtForward
source · pub trait FmtForward: Sized {
fn fmt_binary(self) -> FmtBinary<Self>
where
Self: Binary,
{ ... }
fn fmt_display(self) -> FmtDisplay<Self>
where
Self: Display,
{ ... }
fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where
Self: LowerExp,
{ ... }
fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where
Self: LowerHex,
{ ... }
fn fmt_octal(self) -> FmtOctal<Self>
where
Self: Octal,
{ ... }
fn fmt_pointer(self) -> FmtPointer<Self>
where
Self: Pointer,
{ ... }
fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where
Self: UpperExp,
{ ... }
fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where
Self: UpperHex,
{ ... }
fn fmt_list(self) -> FmtList<Self>
where
for<'a> &'a Self: IntoIterator,
{ ... }
}
Expand description
Wraps any value with a format-forward to Debug
.
Provided Methods§
sourcefn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted.
Examples
use wyz::fmt::*;
assert_eq!(
format!("{:?}", 3.fmt_binary()),
"11",
);
sourcefn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted.
Examples
use wyz::fmt::*;
let text = "hello,
world!";
assert_eq!(
format!("{:?}", text),
r#""hello,\nworld!""#,
// the render contains the sequence U+005C REVERSE SOLIDUS,
// then U+006E LATIN SMALL LETTER N, *not* U+000A LINE FEED.
);
assert_eq!(
format!("{:?}", text.fmt_display()),
"hello,\nworld!",
// the render does not have wrapping quotes, and
// the newline is printed directly, not escaped.
);
sourcefn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted.
Examples
use wyz::fmt::*;
assert_eq!(
format!("{:?}", (31.4).fmt_lower_exp()),
"3.14e1",
);
sourcefn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted.
Examples
use wyz::fmt::*;
assert_eq!(
format!("{:?}", 44203.fmt_lower_hex()),
"acab",
);
sourcefn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes self
to use its Octal
implementation when Debug
-formatted.
Examples
use wyz::fmt::*;
assert_eq!(
format!("{:?}", 493.fmt_octal()),
"755",
);
sourcefn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted.
Examples
use wyz::fmt::*;
let val = 6;
let addr = &val as *const i32;
println!("{:?}", addr.fmt_pointer());
// prints a memory address.
sourcefn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted.
Examples
use wyz::fmt::*;
assert_eq!(
format!("{:?}", (62.8).fmt_upper_exp()),
"6.28E1",
);
sourcefn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted.
Examples
use wyz::fmt::*;
assert_eq!(
format!("{:?}", 55322.fmt_upper_hex()),
"D81A",
);
sourcefn fmt_list(self) -> FmtList<Self>where
for<'a> &'a Self: IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
for<'a> &'a Self: IntoIterator,
Formats each item in a sequence.
This wrapper structure conditionally implements all of the formatting
traits when self
can be viewed as an iterator whose items implement
them. It iterates over &self
and prints each item according to the
formatting specifier provided.
Examples
use wyz::fmt::*;
let seq = [10, 20, 30, 40];
assert_eq!(
format!("{:?}", seq.fmt_list().fmt_lower_hex()),
"[a, 14, 1e, 28]",
);