-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
"dataless", | ||
"deserializations", | ||
"docsrs", | ||
"formatdoc", | ||
"impls", | ||
"indoc", | ||
"ipnetwork", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//! Checks "untagged enum" behavior / fall-through when deserializing. | ||
|
||
use confik::{Configuration, TomlSource}; | ||
|
||
#[derive(Debug, serde::Deserialize)] | ||
#[serde(untagged)] | ||
enum S3Auth { | ||
K8sServiceAccount { | ||
use_k8s_service_account: serde_bool::True, | ||
}, | ||
|
||
ApiKey { | ||
access_key: String, | ||
access_secret: String, | ||
}, | ||
} | ||
|
||
impl Configuration for S3Auth { | ||
type Builder = Option<Self>; | ||
} | ||
|
||
#[derive(Debug, Configuration)] | ||
struct Config { | ||
s3_auth: S3Auth, | ||
} | ||
|
||
fn main() { | ||
let config = indoc::formatdoc! {" | ||
[s3_auth] | ||
use_k8s_service_account = false | ||
"}; | ||
Config::builder() | ||
.override_with(TomlSource::new(config)) | ||
.try_build() | ||
.expect_err("Successfully built with incorrect boolean inner value"); | ||
|
||
let config = indoc::formatdoc! {" | ||
[s3_auth] | ||
use_k8s_service_account = true | ||
"}; | ||
let config = Config::builder() | ||
.override_with(TomlSource::new(config)) | ||
.try_build() | ||
.expect("Failed to build"); | ||
assert_matches::assert_matches!(config.s3_auth, S3Auth::K8sServiceAccount { .. }); | ||
|
||
let config = indoc::formatdoc! {" | ||
[s3_auth] | ||
access_key = \"foo\" | ||
access_secret = \"bar\" | ||
"}; | ||
let config = Config::builder() | ||
.override_with(TomlSource::new(config)) | ||
.try_build() | ||
.expect("Failed to build"); | ||
assert_matches::assert_matches!(config.s3_auth, S3Auth::ApiKey { .. }); | ||
} | ||
|
||
// /// Only successfully deserializes from a `true` value boolean. | ||
// struct True; | ||
|
||
// impl serde::Deserialize for True {} | ||
|
||
// impl config::Configuration for True { | ||
// type Builder = Option<Self>; | ||
// } |