pub struct RegistryIndex<'gctx> {
source_id: SourceId,
path: Filesystem,
summaries_cache: RefCell<HashMap<InternedString, Rc<Summaries>>>,
summaries_inflight: RefCell<HashMap<InternedString, Vec<Sender<Rc<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:
LocalRegistryis a simple on-disk tree of files of the raw index.RemoteRegistryis stored as a raw git repository.HttpRegistryfills 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: FilesystemRoot directory of the index for the registry.
summaries_cache: RefCell<HashMap<InternedString, Rc<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.
summaries_inflight: RefCell<HashMap<InternedString, Vec<Sender<Rc<Summaries>>>>>Requests that are currently running.
gctx: &'gctx GlobalContextGlobalContext reference for convenience.
cache_manager: CacheManager<'gctx>Manager of on-disk caches.
Implementations§
Source§impl<'gctx> RegistryIndex<'gctx>
impl<'gctx> RegistryIndex<'gctx>
Sourcepub fn new(
source_id: SourceId,
path: &Filesystem,
gctx: &'gctx GlobalContext,
) -> RegistryIndex<'gctx>
pub fn new( source_id: SourceId, path: &Filesystem, gctx: &'gctx GlobalContext, ) -> RegistryIndex<'gctx>
Creates an empty registry index at path.
Sourcepub async fn hash(
&self,
pkg: PackageId,
load: &dyn RegistryData,
) -> CargoResult<String>
pub async fn hash( &self, pkg: PackageId, load: &dyn RegistryData, ) -> CargoResult<String>
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.
Sourceasync fn summaries<'a, 'b>(
&'a self,
name: InternedString,
req: &'b OptVersionReq,
load: &dyn RegistryData,
) -> CargoResult<impl Iterator<Item = IndexSummary> + 'b>where
'a: 'b,
async fn summaries<'a, 'b>(
&'a self,
name: InternedString,
req: &'b OptVersionReq,
load: &dyn RegistryData,
) -> CargoResult<impl Iterator<Item = IndexSummary> + 'b>where
'a: 'b,
Load a list of summaries for name package in this registry which
match req.
This function will semantically
- parse the index file (either raw or cache),
- match all versions,
- 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.
Sourceasync fn load_summaries(
&self,
name: InternedString,
load: &dyn RegistryData,
) -> CargoResult<Rc<Summaries>>
async fn load_summaries( &self, name: InternedString, load: &dyn RegistryData, ) -> CargoResult<Rc<Summaries>>
Actually parses what summaries we have available.
If Cargo has run previously, this tries in this order:
-
Returns from in-memory cache, aka
RegistryIndex::summaries_cache. -
If missing, hands over to
Summaries::parseto parse an index file.The actual kind index file being parsed depends on which kind of
RegistryDatatheloadargument is given. For example, a Git-basedRemoteRegistrywill 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.
async fn load_summaries_uncached( &self, name: InternedString, load: &dyn RegistryData, ) -> CargoResult<Rc<Summaries>>
Sourcepub fn clear_summaries_cache(&self)
pub fn clear_summaries_cache(&self)
Clears the in-memory summaries cache.
pub async fn query_inner( &self, name: InternedString, req: &OptVersionReq, load: &dyn RegistryData, f: &mut dyn FnMut(IndexSummary), ) -> CargoResult<()>
Sourceasync fn query_inner_with_online(
&self,
name: InternedString,
req: &OptVersionReq,
load: &dyn RegistryData,
f: &mut dyn FnMut(IndexSummary),
online: bool,
) -> CargoResult<()>
async fn query_inner_with_online( &self, name: InternedString, req: &OptVersionReq, load: &dyn RegistryData, f: &mut dyn FnMut(IndexSummary), online: bool, ) -> 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.
Sourcepub async fn is_yanked(
&self,
pkg: PackageId,
load: &dyn RegistryData,
) -> CargoResult<bool>
pub async fn is_yanked( &self, pkg: PackageId, load: &dyn RegistryData, ) -> 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> UnsafeUnpin for RegistryIndex<'gctx>
impl<'gctx> !UnwindSafe for RegistryIndex<'gctx>
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§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>,
§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: 200 bytes