3 个版本
0.1.2 | 2022年1月7日 |
---|---|
0.1.1 | 2021年8月1日 |
0.1.0 | 2021年6月26日 |
#1034 在 数据结构 中
9KB
71 行
system-config
一个 Rust 库,用于在任何上下文中以及在重启之间在磁盘上存储应用程序属性。
示例
将键值对添加到配置中,并将其写入磁盘...
let mut config = Config::new("system-config-example").unwrap();
config.insert("key1", "value1");
config.insert("key2", "value2");
config.write().unwrap();
然后可以在任何其他时间检索信息,即使在应用程序重启或在不同上下文中。
let config = Config::new("system-config-example").unwrap();
let key1 = config.get("key1").unwrap();
let key2 = config.get("key2").unwrap();
println!("key1: {}", key1);
println!("key2: {}", key2);
为了演示这一点,我创建了一些示例来执行这项操作。
$ cargo run -q --example write
$ cargo run -q --example read
key1: value1
key2: value2
$ cargo run -q --example clear
$ cargo run -q --example read
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', examples/read.rs:6:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
结构
内部,system-config
实际上是对 HashMap
的抽象,它读取和写入其信息,在每个 .read()
和 .write()
时以 yaml 格式写入磁盘。
该文件以 .yaml 格式写入您的配置目录中,由 dirs
crate 找到。
许可协议
MIT License
Copyright (c) 2021 Grant Handy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
依赖项
~1.7–2.5MB
~45K SLoC