Field defaults overwrite explicitly selected unit enum variants
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start at the derived Configuration implementation for enums and inspect how contains_non_secret_data() treats unit variants. Add a regression test using the issue’s LogFormat example and field default. Done means the explicitly configured Json value survives try_build() instead of being replaced by Plain.
索引モデルが issue の本文から書いたものです。
説明
The Configuration derive returns false from contains_non_secret_data() for unit enum variants. This causes #[confik(default = …)] to overwrite explicit values—for example, configured LogFormat::Json becomes the default LogFormat::Plain.
An explicitly selected variant should count as supplied data and take precedence over the field default.
This works:
// Cargo.toml:
// confik = "=0.15.12"
// serde = { version = "1", features = ["derive"] }
use confik::{Configuration, TomlSource};
#[derive(Debug, PartialEq, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
enum LogFormat {
Plain,
Json,
}
impl Configuration for LogFormat {
type Builder = Option<Self>;
}
#[derive(Configuration)]
struct Config {
#[confik(default = LogFormat::Plain)]
format: LogFormat,
}
fn main() {
let config = Config::builder()
.override_with(TomlSource::new(r#"format = "json""#))
.try_build()
.unwrap();
assert_eq!(config.format, LogFormat::Json);
}
This doesn’t — a derived implementation with the same field default:
// Cargo.toml: confik = "=0.15.12"
use confik::{Configuration, TomlSource};
#[derive(Debug, PartialEq, Configuration)]
#[confik(forward(serde(rename_all = "lowercase")))]
enum LogFormat {
Plain,
Json,
}
#[derive(Configuration)]
struct Config {
#[confik(default = LogFormat::Plain)]
format: LogFormat,
}
fn main() {
let config = Config::builder()
.override_with(TomlSource::new(r#"format = "json""#))
.try_build()
.unwrap();
// Fails: left is Plain, right is Json.
assert_eq!(config.format, LogFormat::Json);
}
- 主要言語
- Rust
- スター
- 46
- フォーク
- 3
- 平均マージ
- 19時間 35分
- マージ済み PR(30日)
- 27
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
x52dev/confik のほかの issue
-
bug-upstream
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
x52dev/confik#118 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
KDL source supportオープンenhancement
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
servo/rust-smallvec#827 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
nowledge-co/hawdb#1400 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
calcit-lang/caps#16 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
penso/herdr-gpui#934 ·
メンテナーはふだん 1 日以内に返信
-
🎉 Add Bossanovaオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
jaywcjlove/awesome-mac#4096 ·
メンテナーはふだん 1 日以内に返信