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§
- Parse
Error - Error type used in the implementation of
FromStrgenerated by#[derive(FromStr)]
Traits§
- Display
Format - Formatting method used in
#[display(with = ...)]. - From
StrFormat - Parsing method used in
#[display(with = ...)]and#[from_str(with = ...)]. - Into
Result - Trait implemented by the return value of the expression specified in
#[from_str(new = ...)].