cargo::core::registry

Struct PackageRegistry

source
pub struct PackageRegistry<'gctx> {
    gctx: &'gctx GlobalContext,
    sources: SourceMap<'gctx>,
    overrides: Vec<SourceId>,
    source_ids: HashMap<SourceId, (SourceId, Kind)>,
    locked: HashMap<(SourceId, InternedString), Vec<(PackageId, Vec<PackageId>)>>,
    yanked_whitelist: HashSet<PackageId>,
    source_config: SourceConfigMap<'gctx>,
    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 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/patches 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§

§gctx: &'gctx GlobalContext§sources: SourceMap<'gctx>§overrides: Vec<SourceId>

A list of sources which are considered “path-overrides” which take precedent when querying for packages.

§source_ids: HashMap<SourceId, (SourceId, Kind)>

Use for tracking sources that are already loaded into the registry.

§locked: HashMap<(SourceId, InternedString), Vec<(PackageId, Vec<PackageId>)>>

This is constructed via PackageRegistry::register_lock. See also LockedMap.

§yanked_whitelist: HashSet<PackageId>

A group of packages tha allows to use even when yanked.

§source_config: SourceConfigMap<'gctx>§patches: HashMap<CanonicalUrl, Vec<Summary>>

Patches registered during calls to PackageRegistry::patch.

These are available for query after calling PackageRegistry::lock_patches, which locks them all to specific versions.

§patches_locked: bool

Whether patches are locked. That is, they are available to resolution.

See PackageRegistry::lock_patches and PackageRegistry::patch for more.

§patches_available: HashMap<CanonicalUrl, Vec<PackageId>>

Patches available for each source.

This is for determining whether a dependency entry from a lockfile happened through [patch], during calls to lock to rewrite summaries to point directly at these patched entries.

This is constructed during calls to PackageRegistry::patch, along with the patches field, thoough these entries never get locked.

Implementations§

source§

impl<'gctx> PackageRegistry<'gctx>

source

pub fn new_with_source_config( gctx: &'gctx GlobalContext, source_config: SourceConfigMap<'gctx>, ) -> CargoResult<PackageRegistry<'gctx>>

source

pub fn get(self, package_ids: &[PackageId]) -> CargoResult<PackageSet<'gctx>>

source

fn ensure_loaded(&mut self, namespace: SourceId, kind: Kind) -> CargoResult<()>

Ensures the Source of the given SourceId is loaded. If not, this will block until the source is ready.

source

pub fn add_sources( &mut self, ids: impl IntoIterator<Item = SourceId>, ) -> CargoResult<()>

source

pub fn add_preloaded(&mut self, source: Box<dyn Source + 'gctx>)

Adds a source which will be locked. Useful for path sources such as the source of a workspace member.

source

fn add_source(&mut self, source: Box<dyn Source + 'gctx>, kind: Kind)

Adds a source to the registry.

source

pub fn add_override(&mut self, source: Box<dyn Source + 'gctx>)

Adds a source from a path override.

source

pub fn add_to_yanked_whitelist(&mut self, iter: impl Iterator<Item = PackageId>)

Allows a group of package to be available to query even if they are yanked.

source

pub fn clear_lock(&mut self)

remove all residual state from previous lock files.

source

pub fn register_lock(&mut self, id: PackageId, deps: Vec<PackageId>)

Registers one “locked package” to the registry, for guiding the dependency resolution. See LockedMap for more.

source

pub fn patch( &mut self, url: &Url, patch_deps: &[PatchDependency<'_>], ) -> 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 patch_deps will be resolved to a precise version and stored internally for future calls to query below.

Note that the patch list specified here will not be available to Registry::query until PackageRegistry::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.

source

pub fn lock_patches(&mut self)

Lock all patch summaries added via patch, making them available to resolution via Registry::query.

source

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.

source

fn load(&mut self, source_id: SourceId, kind: Kind) -> CargoResult<()>

Loads the Source for a given SourceId to this registry, making them available to resolution.

source

fn query_overrides( &mut self, dep: &Dependency, ) -> Poll<CargoResult<Option<IndexSummary>>>

Queries path overrides from this registry.

source

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.

source

fn warn_bad_override( &self, override_summary: &Summary, real_summary: &Summary, ) -> CargoResult<()>

Trait Implementations§

source§

impl<'gctx> Registry for PackageRegistry<'gctx>

source§

fn query( &mut self, dep: &Dependency, kind: QueryKind, f: &mut dyn FnMut(IndexSummary), ) -> Poll<CargoResult<()>>

Attempt to find the packages that match a dependency request.
source§

fn describe_source(&self, id: SourceId) -> String

Gets the description of a source, to provide useful messages.
source§

fn is_replaced(&self, id: SourceId) -> bool

Checks if a source is replaced with some other source.
source§

fn block_until_ready(&mut self) -> CargoResult<()>

Block until all outstanding Poll::Pending requests are Poll::Ready.
source§

fn query_vec( &mut self, dep: &Dependency, kind: QueryKind, ) -> Poll<CargoResult<Vec<IndexSummary>>>

Gathers the result from Registry::query as a list of IndexSummary items when they become available.

Auto Trait Implementations§

§

impl<'gctx> Freeze for PackageRegistry<'gctx>

§

impl<'gctx> !RefUnwindSafe for PackageRegistry<'gctx>

§

impl<'gctx> !Send for PackageRegistry<'gctx>

§

impl<'gctx> !Sync for PackageRegistry<'gctx>

§

impl<'gctx> Unpin for PackageRegistry<'gctx>

§

impl<'gctx> !UnwindSafe for PackageRegistry<'gctx>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

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: 480 bytes