问题描述
我正在使用板条箱 toml = "0.5.8"@H_502_2@ 来解析 TOML 文件。我的预期输出应该存储在这个结构中:
#[derive(Deserialize,Debug)]
pub struct Config {
pub watching: Vec<Stocks>,}
#[derive(Deserialize,Debug)]
pub struct Stocks {
pub symbol: String,}
@H_502_2@
pub fn parse_toml_file(path: String) -> Config {
let content = fs::read_to_string(path).expect("Failed to access file.");
let toml_config: Config = toml::from_str(&content[..]).expect("Failed to parse file.");
toml_config
}
@H_502_2@
这就是我所说的:
let home: String = format!("{:?}",home_dir().unwrap());
let path: String = format!(
"{}/.config/stonks.toml",home[1..home.len() - 1].to_string()
);
let cli = Cli::new(parse_toml_file(path));
@H_502_2@
这是 content@H_502_2@ 变量的值:
"[watching]\nsymbol = [\"AAPL\",\"TSLA\"]\n"
@H_502_2@
这是我在创建 toml_config@H_502_2@ 变量时遇到的错误:
thread 'main' panicked at 'Failed to parse file.: Error { inner: ErrorInner { kind: Custom,line: Some(0),col: 0,at: Some(0),message: "invalid type: map,expected a sequence",key: ["watching"] } }',src/parse.rs:19:60
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@H_502_2@
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)