pub fn concrete_pin_version(
requirement: &str,
ecosystem: EcosystemId,
) -> Option<&str>Expand description
Returns the concrete version text requirement denotes, or None if
requirement is not the shape of a single concrete version.
Any pin marker (=/==, or a single-value bracket wrap like NuGet’s
[1.0.0]) is stripped off. The only shape safe to query OSV with
directly, and, for #233, the only shape safe to compare against a real
registry version string in the yanked-version probe. A wrong answer here
is invisible in testing (OSV silently returns {} for a fabricated
version; the yanked probe silently finds no match), so getting this
right matters more than covering every ecosystem’s full range grammar.
An explicit pin marker is always accepted, and its marker is stripped
from the returned text — required because PyPI’s parser retains the
pep440 comparator in Dependency::version_requirement() (an exact pin
parses to "==4.9.0", not "4.9.0"; confirmed by
deps-pypi’s test_basic_pinned), so comparing the unstripped text
against a real registry version string ("4.9.0") would never match. A
bare requirement (no marker) is returned verbatim, and is accepted only
for ecosystems where a bare version is not itself a range by default
(critique C2) — see bare_version_is_a_range.
§Examples
use deps_core::EcosystemId;
use deps_core::lsp_helpers::concrete_pin_version;
// An explicit pin marker is stripped, for any ecosystem.
assert_eq!(
concrete_pin_version("=1.2.3", EcosystemId::Cargo),
Some("1.2.3")
);
// Cargo's bare version is a caret range by default, not a pin.
assert_eq!(concrete_pin_version("1.2.3", EcosystemId::Cargo), None);
// Maven has no implicit range operator, so a bare version is exact.
assert_eq!(
concrete_pin_version("2.14.1", EcosystemId::Maven),
Some("2.14.1")
);