pub trait ToDisplay {
type Displayer<'a>: Display
where Self: 'a;
// Required method
fn display_with_context(&self, context: Context) -> Self::Displayer<'_>;
// Provided method
fn display(&self) -> Self::Displayer<'_> { ... }
}Expand description
Create a displayable instance for a type.
§Usage:
For example, to display an Option<i32>, use .display() to create an instance that is
Display
use to_display::ToDisplay;
assert_eq!(Some(1u32).display().to_string(), "1");If the returned type implements DisplayConfig, it can be further customized with such
as:
.verbose(): to enable verbose mode..max_items(n): display at mostnitems.- …
To implement ToDisplay for a type that implements Display, use #[derive(ToDisplay)].
It displays an Option as Some(value) or None, if verbose is enabled.
and it displays an Option as - or value, if verbose is disabled.
It displays a Result as Ok(value) or Err(error), if verbose is enabled.
It displays a slice as [value1, value2, ...], if the number of items is less than or equal to
max_items.
Required Associated Types§
Required Methods§
Sourcefn display_with_context(&self, context: Context) -> Self::Displayer<'_>
fn display_with_context(&self, context: Context) -> Self::Displayer<'_>
Return an instance that is Display with a provided Context.
User implements this method to create a customized displayable instance.
This method should be called when a DisplayConfig implementation converts its children
item to a DisplayConfig, to inherit the context.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".