こうせい
A easy-to-use configuration crate with the Rust programming language.
toml
,yaml
,json
configuration type.toml
[dependencies]
kosei = { version = "0.1" }
toml
[dependencies]
kosei = { version = "0.1", features = ["apollo"] }
See
examples
for further use.
Config Entry
``rust
//
Deserializeand
Clone` traits should be applied
struct Entry { ... } ```
```rust
fn basetest() {
// Panic if no such file config/config.yaml
let config: Config
```rust
async fn dynamictest() {
// Create a dynamic config and a watcher
let (config, mut watcher) = DynamicConfig::
```rust
async fn apollotest() {
// First build a ApolloClient
let client = ApolloClient::new("http://localhost:8080")
.appid("114514")
.namespace("test", ConfigType::TOML);
// Create a watcher to fetch apollo config changes at a RealTime
mode.
// Entry
indicates how data should be deserialized.
// The returned config type is DynamicConfig<Entry>
let (config, mut watcher) =
DynamicConfig::
println!("{:?}", config); // Stop watching watcher.stop().unwrap();
// You can start twice even you forget to call stop() watcher.watch().unwrap();
// All changes will be reflected to config in time do_somthing(config); }
```