Crate parse_display

Source
Expand description

This crate provides derive macro Display and FromStr. These macros use common helper attributes to specify the format.

See #[derive(Display)] for details.

§Examples

use parse_display::{Display, FromStr};

#[derive(Display, FromStr, PartialEq, Debug)]
#[display("{a}-{b}")]
struct X {
  a: u32,
  b: u32,
}
assert_eq!(X { a:10, b:20 }.to_string(), "10-20");
assert_eq!("10-20".parse(), Ok(X { a:10, b:20 }));


#[derive(Display, FromStr, PartialEq, Debug)]
#[display(style = "snake_case")]
enum Y {
  VarA,
  VarB,
}
assert_eq!(Y::VarA.to_string(), "var_a");
assert_eq!("var_a".parse(), Ok(Y::VarA));

Structs§

ParseError
Error type used in the implementation of FromStr generated by #[derive(FromStr)]

Traits§

DisplayFormat
Formatting method used in #[display(with = ...)].
FromStrFormat
Parsing method used in #[display(with = ...)] and #[from_str(with = ...)].
IntoResult
Trait implemented by the return value of the expression specified in #[from_str(new = ...)].

Derive Macros§

Display
Derive Display.
FromStr
Derive FromStr.