Comments (2)
The Default
trait doesn't integrate with Figment in any particular way. If you're reading the tips for app authors, you'll see that Default
is implemented as an avenue for having a structure that can be merged into the figment as a default for config values, and it doesn't do anything beyond that.
Having said that, this line in your code is almost certainly not what you want. It's placing the address
and timeout
fields in your top-level config.
Back to the problem at hand. If we look at your figment with its defaults:
let mut config = Figment::new().merge(Serialized::defaults(Config::default()));
config = config.merge(Serialized::defaults(ListenerConfig::default()));
We'll have a figment with the following data after this runs:
default.listeners = [{address: 127.0.0.1:8080, timeout: 300_000}}
default.storage_path = "storage"
default.address = 127.0.0.1:8080
default.timeout = 300_000
Your TOML file as read contains:
default.listeners = [{address: 127.0.0.1:8088}]
When we merge this into the previous figment, we get:
default.listeners = [{address: 127.0.0.1:8088}]
default.storage_path = "storage"
default.address = 127.0.0.1:8080
default.timeout = 300_000
Since the TOML default.listeners
array overrides the previous one. As you can see, the only listener
in the array is incomplete, missing the address
field.
If you want this to work, you probably want to specify a default via serde:
#[derive(Debug, Deserialize, Serialize)]
pub struct ListenerConfig {
pub address: String,
#[serde(default = "ListenerConfig::default_timeout")]
pub timeout: u32,
}
from figment.
Hope the above resolved your question! If not, please feel free to reopen.
from figment.
Related Issues (20)
- Bug in `Value::to_i128` HOT 1
- Feature request: provider for env secret files HOT 5
- Support YAML aliases/anchors HOT 2
- Is this abandoned? HOT 1
- `serde_yaml` version range HOT 1
- Reading single line from file HOT 5
- Unable to prioritise clap arguments over environment variables HOT 2
- How to handle replacement of single config entries inside a nested configuration? HOT 2
- Option to append vectors instead of replacing them. HOT 12
- Feature - set config values by path HOT 4
- Strange behavior with figment.join HOT 1
- Question: Iterator over values and best practices for modification of config HOT 2
- Question: How can I load string vectors from the environment? HOT 2
- Improve clap support recipes HOT 5
- Default value not being loaded HOT 4
- `Env` provider deserializes into unsigned int by force HOT 2
- Get names of expected environment variables HOT 1
- INI format support HOT 3
- Expose coalesce module HOT 3
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 figment.