pub trait FormatterToString {
// Required method
fn to_string<T: Display>(&self, value: T) -> String;
// Provided methods
fn to_string_opt<T: Display>(&self, value: Option<T>) -> String { ... }
fn to_multiline_string<'a, T, I>(&self, items: I) -> String
where T: Display + 'a,
I: IntoIterator<Item = T> { ... }
fn to_multiline_indexed_string<'a, T, I>(&self, items: I) -> String
where T: Display + 'a,
I: IntoIterator<Item = T> { ... }
fn to_table_string<T: Display>(&self, items: &[T]) -> String { ... }
fn to_table_string_custom<T: Display, I: IntoIterator<Item = T>>(
&self,
items: I,
columns: usize,
indent: usize,
brackets: bool,
newlines: bool,
) -> String { ... }
}Expand description
Format fmt::Display values to String, respecting a formatter-style alternate flag.
Implemented for fmt::Formatter (uses fmt::Formatter::alternate), DefaultDisplayFormat
({} only), and AlternateDisplayFormat ({:#} only). List helpers match the behavior of the
former ToMultilineString / ToTableString traits from veilid-core.
Required Methods§
Provided Methods§
Sourcefn to_string_opt<T: Display>(&self, value: Option<T>) -> String
fn to_string_opt<T: Display>(&self, value: Option<T>) -> String
Format Option<> values to String, using FormatterToString::to_string for the inner value.
Sourcefn to_multiline_string<'a, T, I>(&self, items: I) -> Stringwhere
T: Display + 'a,
I: IntoIterator<Item = T>,
fn to_multiline_string<'a, T, I>(&self, items: I) -> Stringwhere
T: Display + 'a,
I: IntoIterator<Item = T>,
One line per item, each formatted via FormatterToString::to_string.
Sourcefn to_multiline_indexed_string<'a, T, I>(&self, items: I) -> Stringwhere
T: Display + 'a,
I: IntoIterator<Item = T>,
fn to_multiline_indexed_string<'a, T, I>(&self, items: I) -> Stringwhere
T: Display + 'a,
I: IntoIterator<Item = T>,
Like FormatterToString::to_multiline_string, but each item is prefixed with its index and
indented (four spaces per line of the item’s string form).
Sourcefn to_table_string<T: Display>(&self, items: &[T]) -> String
fn to_table_string<T: Display>(&self, items: &[T]) -> String
Format items as a bracketed table with default layout (32 columns, 4-space indent).
Sourcefn to_table_string_custom<T: Display, I: IntoIterator<Item = T>>(
&self,
items: I,
columns: usize,
indent: usize,
brackets: bool,
newlines: bool,
) -> String
fn to_table_string_custom<T: Display, I: IntoIterator<Item = T>>( &self, items: I, columns: usize, indent: usize, brackets: bool, newlines: bool, ) -> String
Format items as a comma-separated table. columns items per row (0 disables wrapping),
each row indented by indent spaces, optionally wrapped in [] and split across lines.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".