pub struct ResolvedPackages { /* private fields */ }Expand description
Collection of resolved packages from a lock file.
Supports multiple versions per package name, returning the highest semver version through public API methods.
§Examples
use deps_core::lockfile::{ResolvedPackages, ResolvedPackage, ResolvedSource};
let mut packages = ResolvedPackages::new();
packages.insert(
ResolvedPackage::new(
"serde".into(),
"1.0.195".into(),
ResolvedSource::Registry {
url: "https://github.com/rust-lang/crates.io-index".into(),
checksum: "abc123".into(),
},
)
.with_dependencies(vec!["serde_derive".into()]),
);
assert_eq!(packages.version("serde"), Some("1.0.195"));
assert_eq!(packages.len(), 1);Implementations§
Source§impl ResolvedPackages
impl ResolvedPackages
Sourcepub fn insert(&mut self, package: ResolvedPackage)
pub fn insert(&mut self, package: ResolvedPackage)
Inserts a resolved package, storing all versions per name.
Sourcepub fn get(&self, name: &str) -> Option<&ResolvedPackage>
pub fn get(&self, name: &str) -> Option<&ResolvedPackage>
Gets the resolved package with the highest semver version.
Sourcepub fn version(&self, name: &str) -> Option<&str>
pub fn version(&self, name: &str) -> Option<&str>
Gets the highest resolved version string for a package.
Sourcepub fn all(&self, name: &str) -> Option<&[ResolvedPackage]>
pub fn all(&self, name: &str) -> Option<&[ResolvedPackage]>
Returns all stored versions for a package.
Sourcepub fn iter_all(&self) -> impl Iterator<Item = (&String, &[ResolvedPackage])>
pub fn iter_all(&self) -> impl Iterator<Item = (&String, &[ResolvedPackage])>
Returns an iterator yielding every stored version for each unique package name,
unlike Self::iter which collapses each name down to best_package’s single
pick.
The building block for per-occurrence lock-file resolution (issue #649): a caller
disambiguating two manifest occurrences of the same resolved package name (e.g. a
Cargo package = "..." rename pinning an older major alongside a plain dependency
on the current major) needs every retained version for that name, not just the one
Self::iter/Self::into_map would collapse it to.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &ResolvedPackage)>
pub fn iter(&self) -> impl Iterator<Item = (&String, &ResolvedPackage)>
Returns an iterator yielding the best version per unique package name.
Sourcepub fn into_map(self) -> HashMap<String, ResolvedPackage>
pub fn into_map(self) -> HashMap<String, ResolvedPackage>
Converts into a HashMap with the best version per package name.
Trait Implementations§
Source§impl Clone for ResolvedPackages
impl Clone for ResolvedPackages
Source§impl Debug for ResolvedPackages
impl Debug for ResolvedPackages
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Manual, not derived: the HashMap key is the same lock-file package name
ResolvedPackage::name carries, so a derived impl would print it twice — once raw
(as the key) and once through whatever redaction ResolvedPackage’s own Debug applies
(#1319).
Renders through std::fmt::Formatter::debug_map rather than collecting redacted keys
into a real HashMap first: two distinct names that happen to redact to the same marker
(e.g. two different credentials against the same host) would otherwise collide and
silently drop one package from the output.