Give field in struct another valid name when parsing
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3.2k
- Forks
- 265
- Avg merge
- 2h 42m
- Merged PRs (30d)
- 4
Description
I want to use this crate to parse a toml config file. This is part of my current code:
#[derive(Deserialize)]
pub struct ConfigRawFile {
command: Option<String>,
interval: Option<f64>,
fg: Option<String>,
bg: Option<String>,
fg_cursor: Option<String>,
bg_cursor: Option<String>,
bg_selected: Option<String>,
bold: Option<bool>,
bold_cursor: Option<bool>,
keybindings: Option<KeybindingsRaw>,
}
fn parse_toml(config_file: &str) -> Result<ConfigRawFile, config::ConfigError> {
config::Config::builder()
.add_source(config::File::with_name(config_file))
.build()?
.try_deserialize()
}
However, I want to give e.g. bg_cursor a different name that should be read from in the toml file. I would like the toml file to specify "bg+" (which I can't use as a variable name in rust due to the +), and then read that into bg_cursor. Is there an annotation I can use for this (similar to #[arg(long = "bg+", value_name = "COLOR")] in clap)? This would be very useful!
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Config::builder().build()?.try_deserialize() and how ConfigRawFile fields are passed to deserialization. Determine whether field aliases can be supported for keys such as "bg+" while retaining bg_cursor in Rust, then add regression coverage for the requested mapping and verify existing configuration formats remain unaffected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100