Skip to main content

Crate parse_display

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)]

Constants§

ANY_REGEX
Regular expression that matches any string. Equivalent to "(?s:.*?)".

Traits§

DisplayFormat
Formatting method used in #[display(with = ...)].
FromStrFormat
Parsing method used in #[display(with = ...)] and #[from_str(with = ...)].
FromStrRegexstd
A trait for getting regex patterns that match strings parseable by FromStr.
IntoResult
Trait implemented by the return value of the expression specified in #[from_str(new = ...)].

Derive Macros§

Display
Derive Display.
FromStr
Derive FromStr and FromStrRegex.