Skip to main content

declared_in

Function declared_in 

Source
pub fn declared_in(manifest: &str) -> Option<String>
Expand description

The [package] version of a manifest’s text.

The first version = "..." inside [package], which is where the manifest puts it: a dependency pinned at a version further down is a different package, a key that merely begins with version is a different key, and a trailing comment is not part of the value. Read without a TOML parser, because the value wanted is one quoted scalar in a table whose header is unambiguous, and a dependency to read it would be one this crate argues against.

use majordomus_cli::release::version::declared_in;
let manifest = "[package]\nname = \"x\"\nversion = \"1.2.3\"   # bumped\n\n\
                [dependencies]\nserde = { version = \"1.2.4\" }\n";
assert_eq!(declared_in(manifest).as_deref(), Some("1.2.3"));
// outside [package] there is no package version at all
assert_eq!(declared_in("[dependencies]\nversion = \"1.0.0\"\n"), None);
// a key that only starts with the word is another key
assert_eq!(declared_in("[package]\nversioned = \"1.0.0\"\n"), None);