Trait parsel::Display

1.0.0 · source · []
pub trait Display {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>;
}
Expand description

Format trait for an empty format, {}.

Display is similar to Debug, but Display is for user-facing output, and so cannot be derived.

For more information on formatters, see the module-level documentation.

Examples

Implementing Display on a type:

use std::fmt;

struct Point {
    x: i32,
    y: i32,
}

impl fmt::Display for Point {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "({}, {})", self.x, self.y)
    }
}

let origin = Point { x: 0, y: 0 };

assert_eq!(format!("The origin is: {origin}"), "The origin is: (0, 0)");

Required Methods

Formats the value using the given formatter.

Examples
use std::fmt;

struct Position {
    longitude: f32,
    latitude: f32,
}

impl fmt::Display for Position {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "({}, {})", self.longitude, self.latitude)
    }
}

assert_eq!("(1.987, 2.983)",
           format!("{}", Position { longitude: 1.987, latitude: 2.983, }));

Implementors

Prints the token tree as a string that is supposed to be losslessly convertible back into the same token tree (modulo spans), except for possibly TokenTree::Groups with Delimiter::None delimiters and negative numeric literals.

Prints the token tree as a string that is supposed to be losslessly convertible back into the same token tree (modulo spans), except for possibly TokenTree::Groups with Delimiter::None delimiters and negative numeric literals.

Prints the identifier as a string that should be losslessly convertible back into the same identifier.

Prints the group as a string that should be losslessly convertible back into the same group (modulo spans), except for possibly TokenTree::Groups with Delimiter::None delimiters.

Prints the identifier as a string that should be losslessly convertible back into the same identifier.

Prints the literal as a string that should be losslessly convertible back into the same literal (except for possible rounding for floating point literals).

Prints the punctuation character as a string that should be losslessly convertible back into the same character.

Prints the token stream as a string that is supposed to be losslessly convertible back into the same token stream (modulo spans), except for possibly TokenTree::Groups with Delimiter::None delimiters and negative numeric literals.

Write an Ipv6Addr, conforming to the canonical style described by RFC 5952.

Prints the group as a string that should be losslessly convertible back into the same group (modulo spans), except for possibly TokenTree::Groups with Delimiter::None delimiters.

Prints the punctuation character as a string that should be losslessly convertible back into the same character.

Prints the token stream as a string that is supposed to be losslessly convertible back into the same token stream (modulo spans), except for possibly TokenTree::Groups with Delimiter::None delimiters and negative numeric literals.