| Crates.io | to_and_fro |
| lib.rs | to_and_fro |
| version | 0.7.1 |
| created_at | 2023-11-24 05:35:05.172949+00 |
| updated_at | 2025-04-24 05:07:54.66334+00 |
| description | Proc macro for generating implimentations of Display and FromStr for Enum Variants |
| homepage | https://github.com/tascord/ToAndFro |
| repository | https://github.com/tascord/ToAndFro |
| max_upload_size | |
| id | 1046814 |
| size | 33,492 |
Automatic implimentations for Display, FromStr, and others for Enums.
cargo add to_and_fro
#[derive(ToAndFro)]
pub enum TestEnum {
ValueOne,
ValueTwo,
ValueThree
}
TestEnum::ValueOne.to_string() // "ValueOne"
TestEnum::from_str("ValueTwo") // TestEnum::ValueTwo
TestEnum::from_str("ValueFour") // anyhow::Error("Invalid variant ValueFour for enum TestEnum")
#[derive(ToAndFro)]
pub enum TestEnum {
#[input_case("snake")] // FromStr will parse only snake_case input
ValueOne,
#[output_case("kebab")] // Display methods will produce a kebab-case output
ValueTwo,
ValueThree // Defaults to as written input, and as-written output
}
#[derive(ToAndFro)]
#[default("Fallback")]
pub enum TestEnum {
Fallback,
ValueOne,
ValueTwo,
ValueThree
}
TestEnum::from_str("ValueFour") // TestEnum::Fallback
#[derive(ToAndFro)]
pub enum TestEnum {
#[reject]
ValueOne,
ValueTwo
}
TestEnum::from_str("ValueOne") // anyhow::Error("Invalid variant ValueOne for enum TestEnum")
Serialize and Deserialize from serde#[derive(ToAndFro)]
#[serde]
pub enum TestEnum {
ValueOne,
ValueTwo,
ValueThree
}
kebab (heck)pascal (heck)snake (heck)title (heck)train (heck)lower_camel (heck)upper_camel (heck)shouty_kebab (heck)shouty_snake (heck)upper (UPPERCASE)lower (lowercase)percentI appreciate all feedback, in whatever forms they might take.
If you're looking to specifically make a Bug Report, or Suggest a Feature, please do so through their templates in the issues section.