Comments (5)
@amkartashov could you describe your use case in more detail? Maybe some example code how you wish confique
would work?
from confique.
Thanks @LukasKalbertodt
My usecase is to support mutually exclusive sections in config file. I'm writing app which can use different backend types, so it can store blobs on a filesystem or in KV storage or something else.
In config it looks like this (filesystem as backend):
backend:
actions:
module: fs
options:
path: /tmp/cache/ac
blobs:
module: fs
options:
path: /tmp/cache/cas
max_chunk_size: 10000000
or like this (GRPC service as backend for actions, TiKV as backend for blobs)
backend:
actions:
module: grpc
options:
url: grpc://localhost:8980
blobs:
module: tikv
options:
db_url: ...
max_chunk_size: 10000000
As of now, I use serde to parse config file:
#[derive(Debug, Deserialize, Config, Clone)]
pub struct Conf {
...
#[config(nested)]
pub backend: BackendConf,
}
#[derive(Debug, Deserialize, Config, Clone)]
pub struct BackendConf {
...
pub actions: Option<ActionStorageConf>,
pub blobs: Option<BlobStorageConf>,
}
#[derive(Debug, Deserialize, Clone)]
#[serde(tag = "module", content = "options")]
pub enum ActionStorageConf {
#[serde(alias = "fs")]
FS(FsActionStorageConf),
...
}
#[derive(Debug, Deserialize, Clone)]
#[serde(tag = "module", content = "options")]
pub enum BlobStorageConf {
#[serde(alias = "fs")]
FS(FsBlobStorageConf),
...
}
#[derive(Debug, Deserialize, Clone)]
pub struct FsActionStorageConf {
pub path: PathBuf,
}
#[derive(Debug, Deserialize, Clone)]
pub struct FsBlobStorageConf {
pub path: PathBuf,
#[serde(default = "default_fs_blob_max_chunk_size")]
pub max_chunk_size: usize,
}
from confique.
So basically, it works this far with serde, but I can't use confique features like using env vars for example.
from confique.
Thanks for the example! Seems like a useful feature to me. Is probably related to #14. I will dig into this in the future, trying to come up with a nice API. But no promises as to when. For now I'm happy with 0.2.0. Of course if you want to, you can suggest a specific way confique would derive Config
for enums (as comment first, no need to implement it already).
from confique.
Require this (specifically tagging stuff) before I can adopt this crate. Here's some examples of our enums:
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(
untagged,
expecting = "expected a project name or dependency config object"
)]
pub enum ProjectDependsOn {
String(ProjectID),
Object(DependencyConfig),
}
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(
untagged,
expecting = "expected a sequence of globs or a map of projects"
)]
pub enum WorkspaceProjects {
Both {
globs: Vec<FileGlob>,
sources: ProjectsMap,
},
Globs(Vec<FileGlob>),
Sources(ProjectsMap),
}
from confique.
Related Issues (20)
- Express dependencies between fields via attributes (e.g. `requires = "other_field"`)
- Load default values from Rust expressions like constants HOT 1
- Validation HOT 1
- Forward other derives to the partial type? HOT 6
- More file convenience functions ("first found one", `config.{toml,yaml}` syntax, ...)
- Think about interaction with clap to allow loading/overriding config values from CLI args HOT 3
- Feature Request: Template for dotenv configuration format HOT 7
- fmt & clippy & CI HOT 1
- Make `template::format` non-generic and pass `C::META` instead HOT 1
- Warnings about missing docs HOT 5
- Means to customize FormatOptions HOT 2
- Automatic support for `skip_serializing_if` on each field
- Would you consider modification of config files? HOT 6
- Deriving environment variable names from structs HOT 3
- `invalid type: string` when trying to deserialize an enum HOT 1
- Save config as file
- Warning about missing docs (in private items) HOT 1
- env yes|no booleans? HOT 3
- empty strings for env bools HOT 1
- `Hocon` support HOT 2
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 confique.