Skip to main content

ToDisplay

Trait ToDisplay 

Source
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 most n items.

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§

Source

type Displayer<'a>: Display where Self: 'a

Required Methods§

Source

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§

Source

fn display(&self) -> Self::Displayer<'_>

Return an instance that is Display, with a default Context.

User calls this method to build a displayable instance.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ToDisplay for &str

Source§

type Displayer<'a> = &'a &str where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for IpAddr

Source§

type Displayer<'a> = &'a IpAddr where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for SocketAddr

Source§

type Displayer<'a> = &'a SocketAddr where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for bool

Source§

type Displayer<'a> = &'a bool where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for char

Source§

type Displayer<'a> = &'a char where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for f32

Source§

type Displayer<'a> = &'a f32 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for f64

Source§

type Displayer<'a> = &'a f64 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for i8

Source§

type Displayer<'a> = &'a i8 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for i16

Source§

type Displayer<'a> = &'a i16 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for i32

Source§

type Displayer<'a> = &'a i32 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for i64

Source§

type Displayer<'a> = &'a i64 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for i128

Source§

type Displayer<'a> = &'a i128 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for isize

Source§

type Displayer<'a> = &'a isize where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for u8

Source§

type Displayer<'a> = &'a u8 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for u16

Source§

type Displayer<'a> = &'a u16 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for u32

Source§

type Displayer<'a> = &'a u32 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for u64

Source§

type Displayer<'a> = &'a u64 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for u128

Source§

type Displayer<'a> = &'a u128 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for usize

Source§

type Displayer<'a> = &'a usize where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for String

Source§

type Displayer<'a> = &'a String where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for Ipv4Addr

Source§

type Displayer<'a> = &'a Ipv4Addr where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for Ipv6Addr

Source§

type Displayer<'a> = &'a Ipv6Addr where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for SocketAddrV4

Source§

type Displayer<'a> = &'a SocketAddrV4 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for SocketAddrV6

Source§

type Displayer<'a> = &'a SocketAddrV6 where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroI8

Source§

type Displayer<'a> = &'a NonZero<i8> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroI16

Source§

type Displayer<'a> = &'a NonZero<i16> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroI32

Source§

type Displayer<'a> = &'a NonZero<i32> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroI64

Source§

type Displayer<'a> = &'a NonZero<i64> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroI128

Source§

type Displayer<'a> = &'a NonZero<i128> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroIsize

Source§

type Displayer<'a> = &'a NonZero<isize> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroU8

Source§

type Displayer<'a> = &'a NonZero<u8> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroU16

Source§

type Displayer<'a> = &'a NonZero<u16> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroU32

Source§

type Displayer<'a> = &'a NonZero<u32> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroU64

Source§

type Displayer<'a> = &'a NonZero<u64> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroU128

Source§

type Displayer<'a> = &'a NonZero<u128> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl ToDisplay for NonZeroUsize

Source§

type Displayer<'a> = &'a NonZero<usize> where Self: 'a

Source§

fn display_with_context(&self, _context: Context) -> Self::Displayer<'_>

Source§

impl<K, V> ToDisplay for BTreeMap<K, V>
where K: ToDisplay, V: ToDisplay,

Source§

type Displayer<'a> = DisplayBTreeMap<'a, K, V> where K: 'a, V: 'a

Source§

fn display_with_context(&self, context: Context) -> Self::Displayer<'_>

Source§

impl<T> ToDisplay for Option<T>
where T: ToDisplay,

Source§

type Displayer<'a> = DisplayOption<'a, T> where T: 'a

Source§

fn display_with_context(&self, context: Context) -> Self::Displayer<'_>

Source§

impl<T> ToDisplay for [T]
where T: ToDisplay,

Source§

type Displayer<'a> = DisplaySlice<'a, T> where T: 'a

Source§

fn display_with_context(&self, context: Context) -> Self::Displayer<'_>

Source§

impl<T> ToDisplay for Vec<T>
where T: ToDisplay,

Source§

type Displayer<'a> = DisplaySlice<'a, T> where T: 'a

Source§

fn display_with_context(&self, context: Context) -> Self::Displayer<'_>

Source§

impl<T, E> ToDisplay for Result<T, E>
where T: ToDisplay, E: Display,

Source§

type Displayer<'a> = DisplayResult<'a, T, E> where T: 'a, E: 'a

Source§

fn display_with_context(&self, context: Context) -> Self::Displayer<'_>

Implementors§