rust - 使用数组类型加载 yaml 配置
问题描述
我正在编写一个代码,我试图加载 config.yaml 文件
impl ::std::default::Default for MyConfig {
fn default() -> Self { Self { foo: "".into(), conf: vec![] } }
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MyConfig {
foo: String,
conf: Vec<String>
}
let cfg: MyConfig = confy::load("config")?;
println!("{:#?}", cfg);
配置.yaml 文件
foo: "test"
conf:
gg
gb
gg
bb
输出
MyConfig {
url: "",
jobs: [],
}
我将 config.yaml 文件保存在调用它的同一文件夹中。看起来它无法加载文件本身。那里错过了什么?
编辑:当我将扩展名从 yaml 更改为 toml 并提供完整路径时,它找到了文件,但预期的结构是
配置文件
foo = "test"
conf = ["gg","gb","gv","gx"]
完整路径
confy::load("c:/test/config")?;
尝试了多个地方来保留它但没有得到它,看起来它需要完整路径。
但我得到了输出
MyConfig {
url: "test",
jobs: [
"gg",
"gb",
"gv",
"gx",
],
}
解决方案
我认为它应该格式化如下:
foo: "test"
conf:
- gg
- gb
- gg
- bb
推荐阅读
- css - css 悬停动画在 ie11 中不起作用。将鼠标悬停在 IE 中不起作用的元素上时的 CSS 过渡
- python - 如何判断一个可迭代对象是否只能迭代一次?
- react-native - 如何使用 Detox 单击此对话框?明显的解决方案,但我仍然无法点击它
- reactjs - VSCode 没有正确格式化 JSX
- visual-studio - 在 Visual Studio 2019 中使用 libcurl 时生成错误
- jquery - 我想在 mysql 上获得重复记录
- python - (Swagger 2.0/ Connexion)无类型不是“字符串”类型
- makefile - csh 中需要 makefile 中的变量
- c# - .NET Core 查询到 Postgres 的可选过滤器?
- matlab - Matlab - 三个(或更多)子图,带有单一颜色条和通用色标