#display #from-str #regex #enums #derive #proc-macro

macro parse-display-derive

Procedural macro to implement Display and FromStr using common settings

22 releases

0.10.0 Aug 4, 2024
0.9.1 May 30, 2024
0.9.0 Feb 4, 2024
0.8.2 Jul 16, 2023
0.1.0 Jun 15, 2019

#1014 in Procedural macros

Download history 51635/week @ 2024-08-22 63622/week @ 2024-08-29 61782/week @ 2024-09-05 49584/week @ 2024-09-12 49747/week @ 2024-09-19 60044/week @ 2024-09-26 55677/week @ 2024-10-03 54143/week @ 2024-10-10 64163/week @ 2024-10-17 67428/week @ 2024-10-24 61441/week @ 2024-10-31 61589/week @ 2024-11-07 62351/week @ 2024-11-14 66122/week @ 2024-11-21 63610/week @ 2024-11-28 58196/week @ 2024-12-05

261,138 downloads per month
Used in 255 crates (4 directly)

MIT/Apache

81KB
2.5K SLoC

parse-display

Crates.io Docs.rs Actions Status

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

Install

Add this to your Cargo.toml:

[dependencies]
parse-display = "0.10.0"

Documentation

See #[derive(Display)] documentation for details.

Example

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

License

This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2.3–4MB
~70K SLoC