Skip to main content

apply_fetch_outcomes

Function apply_fetch_outcomes 

Source
pub fn apply_fetch_outcomes(
    outcomes: &mut DependencyOutcomes,
    yanked_versions: HashMap<PackageName, (ConcreteVersion, RemovalStatus)>,
    fetch_failed: HashMap<PackageName, FetchFailure>,
    collided_names: HashSet<PackageName>,
    formatter: &dyn EcosystemFormatter,
)
Expand description

Re-keys a completed fetch’s yanked/fetch-failure findings from raw to normalized package names and applies them to outcomes.

Also records every collided name (two occurrences resolving to different sources, dedup_dependencies_by_source) as not-attempted.

set_fetch_failure_if_absent (not set_fetch_failure) for collided_names: a collided name normalizing to the same key as a genuine failure just recorded above must not clobber it (impl-critic M2).

§Examples

use deps_core::lsp_helpers::{
    DependencyOutcomes, DiagnosticMessages, DiagnosticPolicy, OsvNaming, PackageNaming,
    PackageRendering, RequirementResolution, SourcePolicy,
};
use deps_core::{ConcreteVersion, PackageName, RemovalStatus};
use deps_engine::classify::fetch::apply_fetch_outcomes;
use std::collections::{HashMap, HashSet};

struct SimpleFormatter;
impl PackageNaming for SimpleFormatter {}
impl PackageRendering for SimpleFormatter {
    fn format_version_for_text_edit(&self, version: &ConcreteVersion) -> String {
        version.to_string()
    }
    fn package_url(&self, name: &PackageName) -> String {
        name.as_str().to_string()
    }
}
impl RequirementResolution for SimpleFormatter {}
impl DiagnosticMessages for SimpleFormatter {}
impl DiagnosticPolicy for SimpleFormatter {}
impl SourcePolicy for SimpleFormatter {}
impl OsvNaming for SimpleFormatter {}

let mut outcomes = DependencyOutcomes::new();
let mut yanked = HashMap::new();
yanked.insert(
    PackageName::new("time"),
    (ConcreteVersion::from("0.1.43"), RemovalStatus::Yanked),
);

apply_fetch_outcomes(
    &mut outcomes,
    yanked,
    HashMap::new(),
    HashSet::new(),
    &SimpleFormatter,
);

assert_eq!(
    outcomes.yanked("time").map(|(v, _)| v.to_string()),
    Some("0.1.43".to_string())
);