0

我编写 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

我该怎么办?

4

1 回答 1

1

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

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

花括号之间不允许有换行符,除非它们在值内有效。即便如此,强烈建议不要将内联表拆分为多行。如果您发现自己被这种愿望所困扰,则意味着您应该使用标准桌子。

[dependencies.opencv]
version = "0.26"
default-features = false
features = ["opencv-41"]
于 2020-01-29T13:51:02.453 回答