Crates.io | parse-display-derive |
lib.rs | parse-display-derive |
version | 0.9.1 |
source | src |
created_at | 2019-06-15 17:35:33.496035 |
updated_at | 2024-05-30 18:46:21.328689 |
description | Procedural macro to implement Display and FromStr using common settings. |
homepage | |
repository | https://github.com/frozenlib/parse-display |
max_upload_size | |
id | 141376 |
size | 77,819 |
This crate provides derive macro Display
and FromStr
.
These macros use common helper attributes to specify the format.
Add this to your Cargo.toml:
[dependencies]
parse-display = "0.9.1"
See #[derive(Display)]
documentation for details.
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));
This project is dual licensed under Apache-2.0/MIT. See the two LICENSE-* files for details.
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.