关于Cargo.toml依赖项中的toml换行符

时间:2019-12-08 04:58:01

标签: cargo toml

我写了Cargo.toml的依赖项:

[dependencies ]
opencv = {version = "0.26", default-features = false, features = ["opencv-41"]}

一行以上可以通过编译。

我想分开依赖关系的行。

此页 https://github.com/BurntSushi/toml-test/blob/master/tests/valid/multiline-string.toml

上述解决方案。

我参考此解决方案来编写我的依赖项:

[dependencies ]
opencv = """\{version = "0.26", \
default-features = false, \
features = ["opencv-41"] \
}"""

但是编译器抛出错误:

$ cargo build                                          [±master ●]

error: failed to parse manifest at /home/curlywei/WorkSpace/rust/testcargo/Cargo.toml

Caused by:
  failed to parse the version requirement { version = "0.26", default-features = false, features = ["opencv-41"] } for dependency opencv

Caused by:
  the given version requirement is invalid

我该怎么办?

1 个答案:

答案 0 :(得分:0)

您的链接包含多行字符串的示例,而不是表。在TOML中,内联表可能不包含换行符。

相反,TOML spec建议使用常规表:

[dependencies.opencv]
version = "0.26"
default-features = false
features = ["opencv-41"]