gostd_settings is library for reading and writing properties files. 是一个用于读写属性配置文件的库
```rust use gostdsettings::{Settings, builder}; fn main() { let mut p = builder().filetypeproperties().build(); p.setproperty("HttpPort", "8081"); p.setproperty( "MongoServer", "mongodb://10.11.1.5,10.11.1.6,10.11.1.7/?replicaSet=mytest", ); p.setpropertyslice( "LogLevel", ["Debug", "Info", "Warn"].iter().map(|s| s.tostring()).collect(), ); match p.storetofile("config.properties") { Ok(()) => println!("store to file app.conf success"), Err(err) => println!("store to file app.conf failed: {}", err), } }
// output
$ cat config.properties
HttpPort = 8081
LogLevel = Debug,Info,Warn
MongoServer = mongodb://10.11.1.5,10.11.1.6,10.11.1.7/?replicaSet=mytest
```
```rust use gostdsettings::{builder, Settings}; fn main() -> Result<(), std::io::Error> { let file = "./config.properties"; let mut p = builder().filetype_properties().build();
p.load_from_file(file)?;
if let Some(httpProt) = p.property("HttpPort") {
println!("{}", httpProt)
}
if let Some(logLevel) = p.property_slice("LogLevel") {
println!("{:?}", logLevel)
}
Ok(())
}
// output
8081
["Debug", "Info", "Warn"]
```