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

no-std parse-display

Procedural macro to implement Display and FromStr using common settings

20 releases

0.9.0 Feb 4, 2024
0.8.2 Jul 16, 2023
0.8.1 Jun 10, 2023
0.8.0 Dec 21, 2022
0.1.0 Jun 15, 2019

#174 in Rust patterns

Download history 21956/week @ 2024-01-18 20116/week @ 2024-01-25 24349/week @ 2024-02-01 18049/week @ 2024-02-08 20638/week @ 2024-02-15 23409/week @ 2024-02-22 23409/week @ 2024-02-29 25395/week @ 2024-03-07 28485/week @ 2024-03-14 27581/week @ 2024-03-21 23927/week @ 2024-03-28 21331/week @ 2024-04-04 24502/week @ 2024-04-11 22752/week @ 2024-04-18 25329/week @ 2024-04-25 22295/week @ 2024-05-02

98,025 downloads per month
Used in 142 crates (65 directly)

MIT/Apache

41KB
437 lines

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.9.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.5–4MB
~73K SLoC