Struct cargo::sources::registry::index::RegistryIndex

source ·
pub struct RegistryIndex<'gctx> {
    source_id: SourceId,
    path: Filesystem,
    summaries_cache: HashMap<InternedString, Summaries>,
    gctx: &'gctx GlobalContext,
    cache_manager: CacheManager<'gctx>,
}
Expand description

Manager for handling the on-disk index.

Different kinds of registries store the index differently:

  • LocalRegistry` is a simple on-disk tree of files of the raw index.
  • RemoteRegistry is stored as a raw git repository.
  • HttpRegistry fills the on-disk index cache directly without keeping any raw index.

These means of access are handled via the RegistryData trait abstraction. This transparently handles caching of the index in a more efficient format.

Fields§

§source_id: SourceId§path: Filesystem

Root directory of the index for the registry.

§summaries_cache: HashMap<InternedString, Summaries>

In-memory cache of summary data.

This is keyed off the package name. The Summaries value handles loading the summary data. It keeps an optimized on-disk representation of the JSON files, which is created in an as-needed fashion. If it hasn’t been cached already, it uses RegistryData::load to access to JSON files from the index, and the creates the optimized on-disk summary cache.

§gctx: &'gctx GlobalContext

GlobalContext reference for convenience.

§cache_manager: CacheManager<'gctx>

Manager of on-disk caches.

Implementations§

source§

impl<'gctx> RegistryIndex<'gctx>

source

pub fn new( source_id: SourceId, path: &Filesystem, gctx: &'gctx GlobalContext ) -> RegistryIndex<'gctx>

Creates an empty registry index at path.

source

pub fn hash( &mut self, pkg: PackageId, load: &mut dyn RegistryData ) -> Poll<CargoResult<&str>>

Returns the hash listed for a specified PackageId. Primarily for checking the integrity of a downloaded package matching the checksum in the index file, aka IndexSummary.

source

fn summaries<'a, 'b>( &'a mut self, name: InternedString, req: &'b OptVersionReq, load: &mut dyn RegistryData ) -> Poll<CargoResult<impl Iterator<Item = &'a IndexSummary> + 'b>>
where 'a: 'b,

Load a list of summaries for name package in this registry which match req.

This function will semantically

  1. parse the index file (either raw or cache),
  2. match all versions,
  3. and then return an iterator over all summaries which matched.

Internally there’s quite a few layer of caching to amortize this cost though since this method is called quite a lot on null builds in Cargo.

source

fn load_summaries( &mut self, name: InternedString, load: &mut dyn RegistryData ) -> Poll<CargoResult<&mut Summaries>>

Actually parses what summaries we have available.

If Cargo has run previously, this tries in this order:

  1. Returns from in-memory cache, aka RegistryIndex::summaries_cache.

  2. If missing, hands over to Summaries::parse to parse an index file.

    The actual kind index file being parsed depends on which kind of RegistryData the load argument is given. For example, a Git-based RemoteRegistry will first try a on-disk index cache file, and then try parsing registry raw index from Git repository.

In effect, this is intended to be a quite cheap operation.

source

pub fn clear_summaries_cache(&mut self)

Clears the in-memory summaries cache.

source

pub fn query_inner( &mut self, name: InternedString, req: &OptVersionReq, load: &mut dyn RegistryData, f: &mut dyn FnMut(IndexSummary) ) -> Poll<CargoResult<()>>

Attempts to find the packages that match a name and a version req.

This is primarily used by Source::query.

source

fn query_inner_with_online( &mut self, name: InternedString, req: &OptVersionReq, load: &mut dyn RegistryData, f: &mut dyn FnMut(IndexSummary), online: bool ) -> Poll<CargoResult<()>>

Inner implementation of Self::query_inner. Returns the number of summaries we’ve got.

The online controls whether Cargo can access the network when needed.

source

pub fn is_yanked( &mut self, pkg: PackageId, load: &mut dyn RegistryData ) -> Poll<CargoResult<bool>>

Looks into the summaries to check if a package has been yanked.

Auto Trait Implementations§

§

impl<'gctx> Freeze for RegistryIndex<'gctx>

§

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

§

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

§

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

§

impl<'gctx> Unpin for RegistryIndex<'gctx>

§

impl<'gctx> !UnwindSafe for RegistryIndex<'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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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