Comments (10)
All code are string-ed rightaway.
For reference the INI support is being refactored a little here: #470
That doesn't change the logic you draw attention to though. The reason we are calling .to_owned()
there is because rust-ini
is used and it provides an iterator over &str
, there is no type information available. To "import" that data we need to create a copy of the strings it provides.
The other formats often parse the strings themselves and provide a Value
enum that can then be mapped into the equivalent for config-rs
(which normalizes Value
type for internal use).
Should it be parsed like this?:
Yes, that sort of improvement could probably be added to (or after) the referenced refactor PR. It is intended for 0.14
so as a breaking change would be ok AFAIK, @matthiasbeyer ?
It can be a bit problematic depending on the value I think 🤷♂️
- A
"0"
or"1"
could "deserialize" into abool
that can be converted to0
/1
number type of a config struct. - But a string that intentionally begins with
0
like a phone number would lose that information, even if the config struct from the user is a string type? I think this is why you'll find other formats that do provide a value type tend to map into an equivalentconfig-rs
value, sorust-ini
providing strings and converting to strings still seems appropriate.
Here a string to a float:
Lines 521 to 540 in b3bda2c
and likewise string (or whatever other intermediary value in our container) to a bool type of the user config struct:
Lines 233 to 245 in b3bda2c
I think the issue is more related to that area, than rust-ini
and if you attempt to fix it with the ini format you risk introducing regressions and less flexibility 😅
from config-rs.
For now, I'll just refer to my commit in my fork. After this is fixed/refactored as a whole, will switch back.
from config-rs.
Hi, thanks for reporting this! A PR would be awesome of course!
, but confuse with master branch status I faced unexpected error,
What do you mean by this?
from config-rs.
I created my own test code, test it on master branch got error missing field 'field_name'
, switched to v0.13.4 got no error. The test was for loading configs from .env/.ini file.
from config-rs.
The last CI run on master is green though.
from config-rs.
Here is my test code:
// tests/file_env_test.rs
use config::{
builder::DefaultState, Config, ConfigBuilder, ConfigError, Environment, File, FileFormat,
};
use serde::Deserialize;
use std::fmt::{Debug, Display};
const ALL_CFG_FILE: &str = "./tests/all.env";
#[derive(Debug, Deserialize)]
struct TestConfig {
#[serde(alias = "TEST__NUMBER")]
pub number: i32,
#[serde(alias = "TEST__STRING")]
pub string: String,
#[serde(alias = "TEST__FLOAT")]
pub float: f32,
#[serde(alias = "TEST__BOOLEAN")]
pub boolean: bool,
}
#[test]
fn test_file_config_success() {
let cfg = Config::builder()
.add_source(config::File::new(ALL_CFG_FILE, FileFormat::Ini))
.build()
.unwrap()
.try_deserialize::<TestConfig>();
dbg!(&cfg);
assert!(cfg.is_ok());
}
ini file
tests/all.env
TEST__NUMBER=123
TEST__STRING=this is string from file
TEST__FLOAT=123.3
TEST__BOOLEAN=true
My original issue is about type incompatibility on nested configs parsing from .ini file.
Above test code is only to test between master and v0.13.4, but found said error(missing field) on master.
from config-rs.
There're many commits unmerged from v0.13.4 into master, hence different version.
from config-rs.
This is the my commit id: e30debf
from config-rs.
Okay, then I'll just need to use that version after release.
from config-rs.
when I flatten the structs into another struct, type conversion failed
I believe there are other issues related to serde deserializing (the internal value.rs
representation, into user struct) within the project?
- #88
- #336
- Potentially related issue for
#[serde(rename=value)]
due to internal feature: #417 (comment) - Another issue with deserializing (proposes solution, but changes since may have affected the viability): #461 (comment)
I'll just need to use that version after release.
I don't know if your concern will be fixed. Addressing INI to parse from &str
to a ValueKind
may fix your concern, but replace it with a regression that impacts others, which is not really a fix.
The value should already be captured into Value
(value.rs
) as a String and from there to the desired type. The fix you want should be handled there instead, but as shown above there are some cases where serde or the internal usage of it within config-rs
is not compatible with some serde attributes like #[serde(flatten)]
.
Some formats are also known to be lossy in conversion into the config-rs
Value
container.
from config-rs.
Related Issues (20)
- Non-deterministic selection of deserializer
- Enum variant aliases don't work HOT 1
- Add a `cargo check-external-types` lint in CI
- Implement serde::Serialize for Config HOT 3
- New release/sync from master HOT 5
- Remove lazy_static HOT 1
- Nom is included in public API HOT 6
- bug: Using the `serde` attribute `rename` fails since `0.14.0` with a `missing field` error HOT 4
- 0.14 pulls in CC0 license HOT 2
- bug: config `0.14.0` only supports lowercase fields (regression since `0.13.4`) HOT 8
- ux: Lack of key and origin in ConfigError::Message leads to uncertain sources from serde error messages HOT 1
- using Environment source to get List of struct HOT 1
- Very old version of async_trait crate is used HOT 2
- Incorrect description of separator usage in Environment::with_prefix()
- ron Deserialize fails with enum with named fields HOT 2
- Unreachable code fault at config-0.14.0/src/file/format/yaml.rs:53:26 HOT 2
- rust-ini version mismatch in github code and crates.io HOT 3
- Maintainer wanted HOT 10
- cargo-audit reports that `yaml-rust` is unmaintained HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from config-rs.