Crates.io | maydon |
lib.rs | maydon |
version | |
source | src |
created_at | 2025-02-17 00:44:59.568148+00 |
updated_at | 2025-02-17 00:44:59.568148+00 |
description | Generating enumation for fields of a struct |
homepage | https://github.com/rust-lang-uz/maydon |
repository | https://github.com/rust-lang-uz/maydon |
max_upload_size | |
id | 1558313 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Upon writing some rusty code for CLI config management, I simply declared a struct like this:
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
pub url: String,
pub port: u16,
pub database_url: String,
pub threads: u16,
}
Also, in order to have set function with proper typed selection, I declared another enum named Field
:
pub enum Field {
Url,
Port,
Database,
Unknown,
Threads,
}
The thing is, I wanted to automate creation of enum generation. Ordinary macros wouldn't be a good viable solution, so I wrote maydon from ground up. I might be missing something or prequisites, but this is what I came up with:
use maydon::Maydon;
#[derive(Maydon)]
#[field_name = "Selector"]
pub struct Config {
pub url: String,
pub port: u16,
}
// The macro should generate:
fn main() {
let _ = Selector::Url;
let _ = Selector::Port;
let _ = Selector::Unknown;
}
This project is licensed under the MIT or Apache-2.0 license - see the LICENSE-MIT or LICENSE-APACHE file for details.