> import json
> with open("config.json") as f:
> contents = f.read()
> config = json.loads(contents)
translates to:
extern crate serde_json as json;
fn read_json() -> Result<json::Value, Box<std::error::Error>> {
let file = std::fs::File::open("config.json")?;
let config = json::from_reader(&file)?;
Ok(config)
}
And
> import configparser
> config = ConfigParser()
> config.read("config.conf")
can be translated to:
extern crate config;
use config::{Config, File, FileFormat};
fn read_config() -> Result<Config, Box<std::error::Error>> {
let mut c = Config::new();
c.merge(File::new("config", FileFormat::Json))?;
Ok(c)
}
Difficult stuff indeed.