Skip to main content

RequirementMatcher

Trait RequirementMatcher 

Source
pub trait RequirementMatcher: Send + Sync {
    // Required method
    fn matches(&self, version: &ConcreteVersion) -> Option<bool>;
}
Expand description

A requirement compiled by one ecosystem, ready to test candidate versions against.

Produced by formatter::RequirementResolution::compile_requirement. Kept as a separate object (rather than a single “does any version match” function) so the requirement is parsed once per dependency, and so the scanning loop — including the empty-list guard, the early-exit on first match, and the “skip an unparseable candidate” rule — lives once in requirement_is_unsatisfiable instead of being reimplemented by all eleven ecosystems.

§Examples

use deps_core::lsp_helpers::RequirementMatcher;
use deps_core::ConcreteVersion;

struct ExactMatch(String);

impl RequirementMatcher for ExactMatch {
    fn matches(&self, version: &ConcreteVersion) -> Option<bool> {
        Some(version.as_str() == self.0)
    }
}

let matcher = ExactMatch("1.0.0".to_string());
assert_eq!(matcher.matches(&ConcreteVersion::new("1.0.0")), Some(true));
assert_eq!(matcher.matches(&ConcreteVersion::new("2.0.0")), Some(false));

Required Methods§

Source

fn matches(&self, version: &ConcreteVersion) -> Option<bool>

Tests one candidate version string against the compiled requirement.

Some(true) / Some(false): this candidate provably does / does not satisfy the requirement. None: this candidate string could not be parsed by this ecosystem’s version format (e.g. a PyPI legacy release identifier, a Maven timestamped snapshot qualifier) — the caller skips it and keeps scanning the rest of the list. Never return None to mean “the requirement itself is unusable”; that is formatter::RequirementResolution::compile_requirement’s job, via returning None from that method instead of constructing a matcher at all.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§