configer
A simple configuration management implemented in Rust.
1.Usage
Add this to your Cargo.toml
:
[]
= "0.6"
# Or
# If necessary
= { = "0.6", = ["usetoml"] }
2.APIs
Notes: It's not stable yet and like a toy. Please be careful when using it in a production environment.
2.1.new
let mut configer = new;
2.2.set
- Support nested key settings
2.2.1.Err
let mut configer = new;
let empty_rvt = configer.set;
assert_eq!;
2.2.2.Ok
let mut configer = new;
configer.set.unwrap;
configer.set.unwrap;
let rvt = snowflake_dynamic!.unwrap as i64;
configer.set.unwrap;
configer.set.unwrap;
let pi = PI as f64;
configer.set.unwrap;
configer.set.unwrap;
let now = parse_from_str.unwrap;
configer.set.unwrap;
2.2.3.set_t
- Update signature
@since 0.4.3
let mut configer = new;
// set
// configer.set("io.github.photowey.string", String::from("Hello, Configer!").into()).unwrap();
// set_t
configer.set_t.unwrap;
// set
// configer.set("io.github.photowey.str", "Rust".into()).unwrap();
// set_t
configer.set_t.unwrap;
let rvt = snowflake_dynamic!.unwrap as i64;
configer.set_t.unwrap;
configer.set_t.unwrap;
let pi = PI as f64;
configer.set_t.unwrap;
configer.set_t.unwrap;
let now = parse_from_str.unwrap;
configer.set_t.unwrap;
2.3.get
2.3.1.Err
let mut configer = new;
configer.set.unwrap;
assert_eq!;
2.3.2.Ok
let mut configer = new;
configer.set.unwrap;
configer.set.unwrap;
let rvt = snowflake_dynamic!.unwrap as i64;
configer.set.unwrap;
configer.set.unwrap;
let pi = PI as f64;
configer.set.unwrap;
configer.set.unwrap;
let now = parse_from_str.unwrap;
configer.set.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
2.3.3.Convert
- Convert
&Node
2.3.3.1.Nested
let mut configer = new;
let mut nested = new;
nested.insert;
configer
.set
.unwrap;
let rvt_nested = configer.get;
if let Some = try_nested else
2.3.3.2.Array
let mut configer = new;
let now = 1710265983u32;
let mut array = new;
array.push;
array.push;
configer
.set
.unwrap;
let rvt_array = configer.get;
let mut image = new;
image.push;
image.push;
if let Some = try_array else
2.3.3.3.DateTime
let mut configer = new;
let now = parse_from_str.unwrap;
configer.set.unwrap;
let rvt_time = configer.get;
// match
match rvt_time
// converter
if let Some = try_datetime else
2.3.4.4....
3.Reader
@since 0.3.0
3.1.toml
3.1.1.new
let toml_reader = default;
3.1.2.Read
3.1.2.1.path
let path = "resources/testdata/configer-dev.toml";
let toml_reader = default;
let toml_rvt = toml_reader.read_from_path;
3.1.2.2.file content
let toml_reader = default;
let path = "resources/testdata/configer-dev.toml";
let content = read_to_string.expect;
let toml_from_content_rvt = toml_reader.read_from_str;
4.ConfigerEnvironmentBuilder
@since 0.4.0
4.1.With table
let path = "resources/testdata/configer-dev.toml";
let toml_reader = default;
let toml_rvt = toml_reader.read_from_path;
if let Ok = toml_rvt
panic!
4.2.With registry and path
- Only support
toml
file now.
let path = "resources/testdata/configer-dev.toml";
let toml_reader = default;
let mut registry = default;
registry.register;
let builder_rvt = builder
.with_registry
.with_path
.build;
if let Ok = builder_rvt
panic!
4.3.With table,registry and path
;
let path = "resources/testdata/configer-dev.toml";
let toml_reader = default;
let mut registry = default;
registry.register;
let table = crate try_load_env_variables;
let builder_rvt = builder
.with_table
.with_registry
.with_path
.build;
if let Ok = builder_rvt
panic!
set_var
4.4.With table,registry,path and profiles
@since 0.6.0
;
let path = "resources/testdata/config.toml";
let toml_reader = default;
let mut registry = default;
registry.register;
let builder_rvt = builder
.with_registry
.with_path
// with profiles
.with_profiles
.build;
if let Ok = builder_rvt
panic!
set_var
5.Load Environment variables
5.1.default
;
let configer = default;
let env_var_rvt = configer.get;
assert_eq!;
set_var
5.2.new
;
let configer = new;
let env_var_rvt = configer.get;
assert_eq!;
set_var
5.3.mixed_with_env_variables
;
let configer = mixed_with_env_variables;
let env_var_rvt = configer.get;
assert_eq!;
set_var
5.4.table
;
let path = "resources/testdata/configer-dev.toml";
let toml_reader = default;
let toml_rvt = toml_reader.read_from_path;
if let Ok = toml_rvt
panic!
set_var
5.5.builder
;
let path = "resources/testdata/configer-dev.toml";
let toml_reader = default;
let mut registry = default;
registry.register;
let builder_rvt = builder
.with_registry
.with_path
.build; // load environment variables auto.
if let Ok = builder_rvt
panic!
set_var
6.Next
- Support load
config
files (P 0).-
configer.toml
-
@since 0.3.0
-
-
configer-${profile}.toml
-
@since 0.6.0
-
ConfigerEnvironmentBuilder
-
with_profiles
-
-
- …
-
yaml
|yml
? -
properties
? -
ini
? -
.env
? -
json
? - …
-
- Auto. load environment variables (P 1)
- Support merge exists
HashMap<String,Node>/Table
- Support bind
struct
- …
7.Documents
Please wait a moment.
8.Test
8.1.cargo test
$ cargo test --features "usetoml" -- --show-output
$ cargo test --features "usetoml"
9.Docs
9.1.features
usetoml
$ cargo doc --open --features usetoml