Struct cargo::core::registry::PackageRegistry
source · pub struct PackageRegistry<'cfg> {
config: &'cfg Config,
sources: SourceMap<'cfg>,
overrides: Vec<SourceId>,
source_ids: HashMap<SourceId, (SourceId, Kind)>,
locked: HashMap<(SourceId, InternedString), Vec<(PackageId, Vec<PackageId>)>>,
yanked_whitelist: HashSet<PackageId>,
source_config: SourceConfigMap<'cfg>,
patches: HashMap<CanonicalUrl, Vec<Summary>>,
patches_locked: bool,
patches_available: HashMap<CanonicalUrl, Vec<PackageId>>,
}
Expand description
This structure represents a registry of known packages. It internally
contains a number of Box<Source>
instances which are used to load a
Package
from.
The resolution phase of Cargo uses this to drive knowledge about new packages as well as querying for lists of new packages. It is here that sources are updated (e.g., network operations) and overrides are handled.
The general idea behind this registry is that it is centered around the
SourceMap
structure, contained within which is a mapping of a SourceId
to
a Source
. Each Source
in the map has been updated (using network
operations if necessary) and is ready to be queried for packages.
Fields§
§config: &'cfg Config
§sources: SourceMap<'cfg>
§overrides: Vec<SourceId>
§source_ids: HashMap<SourceId, (SourceId, Kind)>
§locked: HashMap<(SourceId, InternedString), Vec<(PackageId, Vec<PackageId>)>>
§yanked_whitelist: HashSet<PackageId>
§source_config: SourceConfigMap<'cfg>
§patches: HashMap<CanonicalUrl, Vec<Summary>>
§patches_locked: bool
§patches_available: HashMap<CanonicalUrl, Vec<PackageId>>
Implementations§
source§impl<'cfg> PackageRegistry<'cfg>
impl<'cfg> PackageRegistry<'cfg>
pub fn new(config: &'cfg Config) -> CargoResult<PackageRegistry<'cfg>>
pub fn get(self, package_ids: &[PackageId]) -> CargoResult<PackageSet<'cfg>>
fn ensure_loaded(&mut self, namespace: SourceId, kind: Kind) -> CargoResult<()>
pub fn add_sources( &mut self, ids: impl IntoIterator<Item = SourceId> ) -> CargoResult<()>
pub fn add_preloaded(&mut self, source: Box<dyn Source + 'cfg>)
fn add_source(&mut self, source: Box<dyn Source + 'cfg>, kind: Kind)
pub fn add_override(&mut self, source: Box<dyn Source + 'cfg>)
pub fn add_to_yanked_whitelist(&mut self, iter: impl Iterator<Item = PackageId>)
sourcepub fn clear_lock(&mut self)
pub fn clear_lock(&mut self)
remove all residual state from previous lock files.
pub fn register_lock(&mut self, id: PackageId, deps: Vec<PackageId>)
sourcepub fn patch(
&mut self,
url: &Url,
deps: &[(&Dependency, Option<LockedPatchDependency>)]
) -> CargoResult<Vec<(Dependency, PackageId)>>
pub fn patch( &mut self, url: &Url, deps: &[(&Dependency, Option<LockedPatchDependency>)] ) -> CargoResult<Vec<(Dependency, PackageId)>>
Insert a [patch]
section into this registry.
This method will insert a [patch]
section for the url
specified,
with the given list of dependencies. The url
specified is the URL of
the source to patch (for example this is crates-io
in the manifest).
The deps
is an array of all the entries in the [patch]
section of
the manifest.
Here the deps
will be resolved to a precise version and stored
internally for future calls to query
below. deps
should be a tuple
where the first element is the patch definition straight from the
manifest, and the second element is an optional variant where the
patch has been locked. This locked patch is the patch locked to
a specific version found in Cargo.lock. This will be None
if
Cargo.lock
doesn’t exist, or the patch did not match any existing
entries in Cargo.lock
.
Note that the patch list specified here will not be available to
query
until lock_patches
is called below, which should be called
once all patches have been added.
The return value is a Vec
of patches that should not be locked.
This happens when the patch is locked, but the patch has been updated
so the locked value is no longer correct.
sourcepub fn lock_patches(&mut self)
pub fn lock_patches(&mut self)
Lock all patch summaries added via patch
, making them available to
resolution via query
.
This function will internally lock
each summary added via patch
above now that the full set of patch
packages are known. This’ll allow
us to correctly resolve overridden dependencies between patches
hopefully!
sourcepub fn patches(&self) -> &HashMap<CanonicalUrl, Vec<Summary>>
pub fn patches(&self) -> &HashMap<CanonicalUrl, Vec<Summary>>
Gets all patches grouped by the source URLS they are going to patch.
These patches are mainly collected from patch
.
They might not be the same as patches actually used during dependency resolving.
fn load(&mut self, source_id: SourceId, kind: Kind) -> CargoResult<()>
fn query_overrides( &mut self, dep: &Dependency ) -> Poll<CargoResult<Option<Summary>>>
sourcepub fn lock(&self, summary: Summary) -> Summary
pub fn lock(&self, summary: Summary) -> Summary
This function is used to transform a summary to another locked summary if possible. This is where the concept of a lock file comes into play.
If a summary points at a package ID which was previously locked, then we override the summary’s ID itself, as well as all dependencies, to be rewritten to the locked versions. This will transform the summary’s source to a precise source (listed in the locked version) as well as transforming all of the dependencies from range requirements on imprecise sources to exact requirements on precise sources.
If a summary does not point at a package ID which was previously locked, or if any dependencies were added and don’t have a previously listed version, we still want to avoid updating as many dependencies as possible to keep the graph stable. In this case we map all of the summary’s dependencies to be rewritten to a locked version wherever possible. If we’re unable to map a dependency though, we just pass it on through.
fn warn_bad_override( &self, override_summary: &Summary, real_summary: &Summary ) -> CargoResult<()>
Trait Implementations§
source§impl<'cfg> Registry for PackageRegistry<'cfg>
impl<'cfg> Registry for PackageRegistry<'cfg>
source§fn query(
&mut self,
dep: &Dependency,
kind: QueryKind,
f: &mut dyn FnMut(Summary)
) -> Poll<CargoResult<()>>
fn query( &mut self, dep: &Dependency, kind: QueryKind, f: &mut dyn FnMut(Summary) ) -> Poll<CargoResult<()>>
fn describe_source(&self, id: SourceId) -> String
fn is_replaced(&self, id: SourceId) -> bool
source§fn block_until_ready(&mut self) -> CargoResult<()>
fn block_until_ready(&mut self) -> CargoResult<()>
fn query_vec( &mut self, dep: &Dependency, kind: QueryKind ) -> Poll<CargoResult<Vec<Summary>>>
Auto Trait Implementations§
impl<'cfg> !RefUnwindSafe for PackageRegistry<'cfg>
impl<'cfg> !Send for PackageRegistry<'cfg>
impl<'cfg> !Sync for PackageRegistry<'cfg>
impl<'cfg> Unpin for PackageRegistry<'cfg>
impl<'cfg> !UnwindSafe for PackageRegistry<'cfg>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 432 bytes