pub struct Formatter<'a> { /* private fields */ }
Expand description
Configuration for formatting.
A Formatter
represents various options related to formatting. Users do not
construct Formatter
s directly; a mutable reference to one is passed to
the fmt
method of all formatting traits, like Debug
and Display
.
To interact with a Formatter
, you’ll call various methods to change the
various options related to formatting. For examples, please see the
documentation of the methods defined on Formatter
below.
Implementations§
Source§impl<'a> Formatter<'a>
impl<'a> Formatter<'a>
1.0.0 · Sourcepub fn pad_integral(
&mut self,
is_nonnegative: bool,
prefix: &str,
buf: &str,
) -> Result<(), Error>
pub fn pad_integral( &mut self, is_nonnegative: bool, prefix: &str, buf: &str, ) -> Result<(), Error>
Performs the correct padding for an integer which has already been emitted into a str. The str should not contain the sign for the integer, that will be added by this method.
§Arguments
- is_nonnegative - whether the original integer was either positive or zero.
- prefix - if the ‘#’ character (Alternate) is provided, this is the prefix to put in front of the number.
- buf - the byte array that the number has been formatted into
This function will correctly account for the flags provided as well as the minimum width. It will not take precision into account.
§Examples
use std::fmt;
struct Foo { nb: i32 }
impl Foo {
fn new(nb: i32) -> Foo {
Foo {
nb,
}
}
}
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
// We need to remove "-" from the number output.
let tmp = self.nb.abs().to_string();
formatter.pad_integral(self.nb >= 0, "Foo ", &tmp)
}
}
assert_eq!(format!("{}", Foo::new(2)), "2");
assert_eq!(format!("{}", Foo::new(-1)), "-1");
assert_eq!(format!("{}", Foo::new(0)), "0");
assert_eq!(format!("{:#}", Foo::new(-1)), "-Foo 1");
assert_eq!(format!("{:0>#8}", Foo::new(-1)), "00-Foo 1");
1.0.0 · Sourcepub fn pad(&mut self, s: &str) -> Result<(), Error>
pub fn pad(&mut self, s: &str) -> Result<(), Error>
Takes a string slice and emits it to the internal buffer after applying the relevant formatting flags specified.
The flags recognized for generic strings are:
- width - the minimum width of what to emit
- fill/align - what to emit and where to emit it if the string provided needs to be padded
- precision - the maximum length to emit, the string is truncated if it is longer than this length
Notably this function ignores the flag
parameters.
§Examples
use std::fmt;
struct Foo;
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.pad("Foo")
}
}
assert_eq!(format!("{Foo:<4}"), "Foo ");
assert_eq!(format!("{Foo:0>4}"), "0Foo");
1.0.0 · Sourcepub fn write_str(&mut self, data: &str) -> Result<(), Error>
pub fn write_str(&mut self, data: &str) -> Result<(), Error>
Writes some data to the underlying buffer contained within this formatter.
§Examples
use std::fmt;
struct Foo;
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("Foo")
// This is equivalent to:
// write!(formatter, "Foo")
}
}
assert_eq!(format!("{Foo}"), "Foo");
assert_eq!(format!("{Foo:0>8}"), "Foo");
1.0.0 · Sourcepub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
Glue for usage of the write!
macro with implementors of this trait.
This method should generally not be invoked manually, but rather through
the write!
macro itself.
Writes some formatted information into this instance.
§Examples
use std::fmt;
struct Foo(i32);
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_fmt(format_args!("Foo {}", self.0))
}
}
assert_eq!(format!("{}", Foo(-1)), "Foo -1");
assert_eq!(format!("{:0>8}", Foo(2)), "Foo 2");
1.0.0 · Sourcepub fn flags(&self) -> u32
👎Deprecated since 1.24.0: use the sign_plus
, sign_minus
, alternate
, or sign_aware_zero_pad
methods instead
pub fn flags(&self) -> u32
sign_plus
, sign_minus
, alternate
, or sign_aware_zero_pad
methods insteadReturns flags for formatting.
1.5.0 · Sourcepub fn fill(&self) -> char
pub fn fill(&self) -> char
Returns the character used as ‘fill’ whenever there is alignment.
§Examples
use std::fmt;
struct Foo;
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let c = formatter.fill();
if let Some(width) = formatter.width() {
for _ in 0..width {
write!(formatter, "{c}")?;
}
Ok(())
} else {
write!(formatter, "{c}")
}
}
}
// We set alignment to the right with ">".
assert_eq!(format!("{Foo:G>3}"), "GGG");
assert_eq!(format!("{Foo:t>6}"), "tttttt");
1.28.0 · Sourcepub fn align(&self) -> Option<Alignment>
pub fn align(&self) -> Option<Alignment>
Returns a flag indicating what form of alignment was requested.
§Examples
use std::fmt::{self, Alignment};
struct Foo;
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = if let Some(s) = formatter.align() {
match s {
Alignment::Left => "left",
Alignment::Right => "right",
Alignment::Center => "center",
}
} else {
"into the void"
};
write!(formatter, "{s}")
}
}
assert_eq!(format!("{Foo:<}"), "left");
assert_eq!(format!("{Foo:>}"), "right");
assert_eq!(format!("{Foo:^}"), "center");
assert_eq!(format!("{Foo}"), "into the void");
1.5.0 · Sourcepub fn width(&self) -> Option<usize>
pub fn width(&self) -> Option<usize>
Returns the optionally specified integer width that the output should be.
§Examples
use std::fmt;
struct Foo(i32);
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(width) = formatter.width() {
// If we received a width, we use it
write!(formatter, "{:width$}", format!("Foo({})", self.0), width = width)
} else {
// Otherwise we do nothing special
write!(formatter, "Foo({})", self.0)
}
}
}
assert_eq!(format!("{:10}", Foo(23)), "Foo(23) ");
assert_eq!(format!("{}", Foo(23)), "Foo(23)");
1.5.0 · Sourcepub fn precision(&self) -> Option<usize>
pub fn precision(&self) -> Option<usize>
Returns the optionally specified precision for numeric types. Alternatively, the maximum width for string types.
§Examples
use std::fmt;
struct Foo(f32);
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(precision) = formatter.precision() {
// If we received a precision, we use it.
write!(formatter, "Foo({1:.*})", precision, self.0)
} else {
// Otherwise we default to 2.
write!(formatter, "Foo({:.2})", self.0)
}
}
}
assert_eq!(format!("{:.4}", Foo(23.2)), "Foo(23.2000)");
assert_eq!(format!("{}", Foo(23.2)), "Foo(23.20)");
1.5.0 · Sourcepub fn sign_plus(&self) -> bool
pub fn sign_plus(&self) -> bool
Determines if the +
flag was specified.
§Examples
use std::fmt;
struct Foo(i32);
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
if formatter.sign_plus() {
write!(formatter,
"Foo({}{})",
if self.0 < 0 { '-' } else { '+' },
self.0.abs())
} else {
write!(formatter, "Foo({})", self.0)
}
}
}
assert_eq!(format!("{:+}", Foo(23)), "Foo(+23)");
assert_eq!(format!("{:+}", Foo(-23)), "Foo(-23)");
assert_eq!(format!("{}", Foo(23)), "Foo(23)");
1.5.0 · Sourcepub fn sign_minus(&self) -> bool
pub fn sign_minus(&self) -> bool
Determines if the -
flag was specified.
§Examples
use std::fmt;
struct Foo(i32);
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
if formatter.sign_minus() {
// You want a minus sign? Have one!
write!(formatter, "-Foo({})", self.0)
} else {
write!(formatter, "Foo({})", self.0)
}
}
}
assert_eq!(format!("{:-}", Foo(23)), "-Foo(23)");
assert_eq!(format!("{}", Foo(23)), "Foo(23)");
1.5.0 · Sourcepub fn alternate(&self) -> bool
pub fn alternate(&self) -> bool
Determines if the #
flag was specified.
§Examples
use std::fmt;
struct Foo(i32);
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
if formatter.alternate() {
write!(formatter, "Foo({})", self.0)
} else {
write!(formatter, "{}", self.0)
}
}
}
assert_eq!(format!("{:#}", Foo(23)), "Foo(23)");
assert_eq!(format!("{}", Foo(23)), "23");
1.5.0 · Sourcepub fn sign_aware_zero_pad(&self) -> bool
pub fn sign_aware_zero_pad(&self) -> bool
Determines if the 0
flag was specified.
§Examples
use std::fmt;
struct Foo(i32);
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
assert!(formatter.sign_aware_zero_pad());
assert_eq!(formatter.width(), Some(4));
// We ignore the formatter's options.
write!(formatter, "{}", self.0)
}
}
assert_eq!(format!("{:04}", Foo(23)), "23");
1.2.0 · Sourcepub fn debug_struct<'b>(&'b mut self, name: &str) -> DebugStruct<'b, 'a>
pub fn debug_struct<'b>(&'b mut self, name: &str) -> DebugStruct<'b, 'a>
Creates a DebugStruct
builder designed to assist with creation of
fmt::Debug
implementations for structs.
§Examples
use std::fmt;
use std::net::Ipv4Addr;
struct Foo {
bar: i32,
baz: String,
addr: Ipv4Addr,
}
impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Foo")
.field("bar", &self.bar)
.field("baz", &self.baz)
.field("addr", &format_args!("{}", self.addr))
.finish()
}
}
assert_eq!(
"Foo { bar: 10, baz: \"Hello World\", addr: 127.0.0.1 }",
format!("{:?}", Foo {
bar: 10,
baz: "Hello World".to_string(),
addr: Ipv4Addr::new(127, 0, 0, 1),
})
);
1.2.0 · Sourcepub fn debug_tuple<'b>(&'b mut self, name: &str) -> DebugTuple<'b, 'a>
pub fn debug_tuple<'b>(&'b mut self, name: &str) -> DebugTuple<'b, 'a>
Creates a DebugTuple
builder designed to assist with creation of
fmt::Debug
implementations for tuple structs.
§Examples
use std::fmt;
use std::marker::PhantomData;
struct Foo<T>(i32, String, PhantomData<T>);
impl<T> fmt::Debug for Foo<T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple("Foo")
.field(&self.0)
.field(&self.1)
.field(&format_args!("_"))
.finish()
}
}
assert_eq!(
"Foo(10, \"Hello\", _)",
format!("{:?}", Foo(10, "Hello".to_string(), PhantomData::<u8>))
);
1.2.0 · Sourcepub fn debug_list<'b>(&'b mut self) -> DebugList<'b, 'a>
pub fn debug_list<'b>(&'b mut self) -> DebugList<'b, 'a>
Creates a DebugList
builder designed to assist with creation of
fmt::Debug
implementations for list-like structures.
§Examples
use std::fmt;
struct Foo(Vec<i32>);
impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_list().entries(self.0.iter()).finish()
}
}
assert_eq!(format!("{:?}", Foo(vec![10, 11])), "[10, 11]");
1.2.0 · Sourcepub fn debug_set<'b>(&'b mut self) -> DebugSet<'b, 'a>
pub fn debug_set<'b>(&'b mut self) -> DebugSet<'b, 'a>
Creates a DebugSet
builder designed to assist with creation of
fmt::Debug
implementations for set-like structures.
§Examples
use std::fmt;
struct Foo(Vec<i32>);
impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_set().entries(self.0.iter()).finish()
}
}
assert_eq!(format!("{:?}", Foo(vec![10, 11])), "{10, 11}");
In this more complex example, we use format_args!
and .debug_set()
to build a list of match arms:
use std::fmt;
struct Arm<'a, L, R>(&'a (L, R));
struct Table<'a, K, V>(&'a [(K, V)], V);
impl<'a, L, R> fmt::Debug for Arm<'a, L, R>
where
L: 'a + fmt::Debug, R: 'a + fmt::Debug
{
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
L::fmt(&(self.0).0, fmt)?;
fmt.write_str(" => ")?;
R::fmt(&(self.0).1, fmt)
}
}
impl<'a, K, V> fmt::Debug for Table<'a, K, V>
where
K: 'a + fmt::Debug, V: 'a + fmt::Debug
{
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_set()
.entries(self.0.iter().map(Arm))
.entry(&Arm(&(format_args!("_"), &self.1)))
.finish()
}
}
1.2.0 · Sourcepub fn debug_map<'b>(&'b mut self) -> DebugMap<'b, 'a>
pub fn debug_map<'b>(&'b mut self) -> DebugMap<'b, 'a>
Creates a DebugMap
builder designed to assist with creation of
fmt::Debug
implementations for map-like structures.
§Examples
use std::fmt;
struct Foo(Vec<(String, i32)>);
impl fmt::Debug for Foo {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_map().entries(self.0.iter().map(|&(ref k, ref v)| (k, v))).finish()
}
}
assert_eq!(
format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
r#"{"A": 10, "B": 11}"#
);
Trait Implementations§
Source§impl<'a> Serializer for &mut Formatter<'a>
impl<'a> Serializer for &mut Formatter<'a>
use serde::ser::Serialize;
use serde_derive::Serialize;
use std::fmt::{self, Display};
#[derive(Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum MessageType {
StartRequest,
EndRequest,
}
impl Display for MessageType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.serialize(f)
}
}
Source§type Ok = ()
type Ok = ()
Serializer
during successful
serialization. Most serializers that produce text or binary output
should set Ok = ()
and serialize into an io::Write
or buffer
contained within the Serializer
instance. Serializers that build
in-memory data structures may be simplified by using Ok
to propagate
the data structure around.Source§type SerializeSeq = Impossible<(), Error>
type SerializeSeq = Impossible<(), Error>
serialize_seq
for serializing the content of the
sequence.Source§type SerializeTuple = Impossible<(), Error>
type SerializeTuple = Impossible<(), Error>
serialize_tuple
for serializing the content of
the tuple.Source§type SerializeTupleStruct = Impossible<(), Error>
type SerializeTupleStruct = Impossible<(), Error>
serialize_tuple_struct
for serializing the
content of the tuple struct.Source§type SerializeTupleVariant = Impossible<(), Error>
type SerializeTupleVariant = Impossible<(), Error>
serialize_tuple_variant
for serializing the
content of the tuple variant.Source§type SerializeMap = Impossible<(), Error>
type SerializeMap = Impossible<(), Error>
serialize_map
for serializing the content of the
map.Source§type SerializeStruct = Impossible<(), Error>
type SerializeStruct = Impossible<(), Error>
serialize_struct
for serializing the content of
the struct.Source§type SerializeStructVariant = Impossible<(), Error>
type SerializeStructVariant = Impossible<(), Error>
serialize_struct_variant
for serializing the
content of the struct variant.Source§fn serialize_unit_variant(
self,
_name: &'static str,
_variant_index: u32,
variant: &'static str,
) -> Result<(), Error>
fn serialize_unit_variant( self, _name: &'static str, _variant_index: u32, variant: &'static str, ) -> Result<(), Error>
Source§fn serialize_newtype_struct<T>(
self,
_name: &'static str,
value: &T,
) -> Result<(), Error>
fn serialize_newtype_struct<T>( self, _name: &'static str, value: &T, ) -> Result<(), Error>
struct Millimeters(u8)
. Read moreSource§fn serialize_bytes(self, _v: &[u8]) -> Result<(), Error>
fn serialize_bytes(self, _v: &[u8]) -> Result<(), Error>
Source§fn serialize_newtype_variant<T>(
self,
_name: &'static str,
_variant_index: u32,
_variant: &'static str,
_value: &T,
) -> Result<(), Error>
fn serialize_newtype_variant<T>( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _value: &T, ) -> Result<(), Error>
Source§fn serialize_seq(
self,
_len: Option<usize>,
) -> Result<<&mut Formatter<'a> as Serializer>::SerializeSeq, Error>
fn serialize_seq( self, _len: Option<usize>, ) -> Result<<&mut Formatter<'a> as Serializer>::SerializeSeq, Error>
serialize_element
, then a call to
end
. Read moreSource§fn serialize_tuple(
self,
_len: usize,
) -> Result<<&mut Formatter<'a> as Serializer>::SerializeTuple, Error>
fn serialize_tuple( self, _len: usize, ) -> Result<<&mut Formatter<'a> as Serializer>::SerializeTuple, Error>
serialize_element
,
then a call to end
. Read moreSource§fn serialize_tuple_struct(
self,
_name: &'static str,
_len: usize,
) -> Result<<&mut Formatter<'a> as Serializer>::SerializeTupleStruct, Error>
fn serialize_tuple_struct( self, _name: &'static str, _len: usize, ) -> Result<<&mut Formatter<'a> as Serializer>::SerializeTupleStruct, Error>
struct Rgb(u8, u8, u8)
. This
call must be followed by zero or more calls to serialize_field
, then a
call to end
. Read moreSource§fn serialize_tuple_variant(
self,
_name: &'static str,
_variant_index: u32,
_variant: &'static str,
_len: usize,
) -> Result<<&mut Formatter<'a> as Serializer>::SerializeTupleVariant, Error>
fn serialize_tuple_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _len: usize, ) -> Result<<&mut Formatter<'a> as Serializer>::SerializeTupleVariant, Error>
E::T
in enum E { T(u8, u8) }
. This call must be followed by zero or more calls to
serialize_field
, then a call to end
. Read moreSource§fn serialize_map(
self,
_len: Option<usize>,
) -> Result<<&mut Formatter<'a> as Serializer>::SerializeMap, Error>
fn serialize_map( self, _len: Option<usize>, ) -> Result<<&mut Formatter<'a> as Serializer>::SerializeMap, Error>
serialize_key
and serialize_value
, then a call to end
. Read moreSource§fn serialize_struct(
self,
_name: &'static str,
_len: usize,
) -> Result<<&mut Formatter<'a> as Serializer>::SerializeStruct, Error>
fn serialize_struct( self, _name: &'static str, _len: usize, ) -> Result<<&mut Formatter<'a> as Serializer>::SerializeStruct, Error>
struct Rgb { r: u8, g: u8, b: u8 }
.
This call must be followed by zero or more calls to serialize_field
,
then a call to end
. Read moreSource§fn serialize_struct_variant(
self,
_name: &'static str,
_variant_index: u32,
_variant: &'static str,
_len: usize,
) -> Result<<&mut Formatter<'a> as Serializer>::SerializeStructVariant, Error>
fn serialize_struct_variant( self, _name: &'static str, _variant_index: u32, _variant: &'static str, _len: usize, ) -> Result<<&mut Formatter<'a> as Serializer>::SerializeStructVariant, Error>
E::S
in enum E { S { r: u8, g: u8, b: u8 } }
. This call must be followed by zero or more calls to
serialize_field
, then a call to end
. Read moreSource§fn collect_str<T>(self, value: &T) -> Result<(), Error>
fn collect_str<T>(self, value: &T) -> Result<(), Error>
Display
. Read moreSource§fn collect_seq<I>(self, iter: I) -> Result<Self::Ok, Self::Error>
fn collect_seq<I>(self, iter: I) -> Result<Self::Ok, Self::Error>
Source§fn collect_map<K, V, I>(self, iter: I) -> Result<Self::Ok, Self::Error>
fn collect_map<K, V, I>(self, iter: I) -> Result<Self::Ok, Self::Error>
Source§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Serialize
implementations should serialize in
human-readable form. Read moreAuto Trait Implementations§
impl<'a> Freeze for Formatter<'a>
impl<'a> !RefUnwindSafe for Formatter<'a>
impl<'a> !Send for Formatter<'a>
impl<'a> !Sync for Formatter<'a>
impl<'a> Unpin for Formatter<'a>
impl<'a> !UnwindSafe for Formatter<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.