About toml line break in dependencies of Cargo.toml
Asked Answered
O

1

5

I write dependencies of Cargo.toml :

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

Above one line can pass compilation.

I want to seperate lines for dependencies.

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

said solution.

I refer this solution to write my dependencies:

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

But compiler throw error:

$ 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

How do I do?

Ovida answered 8/12, 2019 at 4:58 Comment(0)
P
7

Your link contains examples of multiline strings, not tables. In TOML, inline tables may not contain newlines.

Instead, the TOML spec suggests using a regular table:

No newlines are allowed between the curly braces unless they are valid within a value. Even so, it is strongly discouraged to break an inline table onto multiples lines. If you find yourself gripped with this desire, it means you should be using standard tables.

[dependencies.opencv]
version = "0.26"
default-features = false
features = ["opencv-41"]
Paucker answered 29/1, 2020 at 13:51 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.