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§

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

Traits§

Derive Macros§