We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
None
Consider the following types:
#[derive(Debug, Deserialize)] struct Config { var: Var, } #[derive(Debug, Deserialize)] struct Var(Option<usize>);
I want to set the Config to { var: Var(None) }, how do I do so?
Config
{ var: Var(None) }
Options I have tried:
var
var: Option<usize>
""
var_0
Example test case: Dependencies:
[dependencies] envious = { version = "0.1.1" } serde = { version = "1", features = ["derive"], default-features = false } [dev-dependencies] temp-env = "0.3"
Code:
use serde::Deserialize; #[derive(Debug, Deserialize)] struct Config { var: Var, } #[derive(Debug, Deserialize)] struct Var(Option<usize>); #[cfg(test)] mod tests { use super::*; #[test] fn unset() { temp_env::with_var("var", Option::<String>::None, || { envious::from_env::<Config>(envious::Prefix::None).unwrap(); }) } #[test] fn empty() { temp_env::with_var("var", Some(""), || { envious::from_env::<Config>(envious::Prefix::None).unwrap(); }) } #[test] fn none() { temp_env::with_var("var", Some("None"), || { envious::from_env::<Config>(envious::Prefix::None).unwrap(); }) } #[test] fn set_0() { temp_env::with_var("var_0", Some("1"), || { envious::from_env::<Config>(envious::Prefix::None).unwrap(); }) } #[test] fn unset_0() { temp_env::with_var("var_0", Option::<String>::None, || { envious::from_env::<Config>(envious::Prefix::None).unwrap(); }) } #[test] fn empty_0() { temp_env::with_var("var_0", Some(""), || { envious::from_env::<Config>(envious::Prefix::None).unwrap(); }) } #[test] fn none_0() { temp_env::with_var("var_0", Some("None"), || { envious::from_env::<Config>(envious::Prefix::None).unwrap(); }) } }
The text was updated successfully, but these errors were encountered:
This is an interesting case.
So the problem stems broadly from the fact that environment variables can either not exist or be a &str.
JSON for example has the null value, which would help deal with it here.
null
I am not sure how to solve it from envious's side. One thing that should work for you, is if you give it a default that returns a None?
envious
Sorry, something went wrong.
It looks like it can work with:
#[derive(Debug, Deserialize)] struct Config { #[serde(default)] var: Var, } #[derive(Default, Debug, Deserialize)] struct Var(Option<usize>);
Might be that's the best that can be done.
No branches or pull requests
Consider the following types:
I want to set the
Config
to{ var: Var(None) }
, how do I do so?Options I have tried:
var
(this works withvar: Option<usize>
and so is what I'd expect to work here),var
toNone
,var
to""
(the empty string),var_0
,var_0
toNone
,var_0
to""
(the empty string).Example test case:
Dependencies:
Code:
The text was updated successfully, but these errors were encountered: