pub struct RegistryIndex<'cfg> {
source_id: SourceId,
path: Filesystem,
summaries_cache: HashMap<InternedString, Summaries>,
config: &'cfg Config,
}
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.
config: &'cfg Config
Config
reference for convenience.
Implementations§
source§impl<'cfg> RegistryIndex<'cfg>
impl<'cfg> RegistryIndex<'cfg>
sourcepub fn new(
source_id: SourceId,
path: &Filesystem,
config: &'cfg Config
) -> RegistryIndex<'cfg>
pub fn new( source_id: SourceId, path: &Filesystem, config: &'cfg Config ) -> RegistryIndex<'cfg>
Creates an empty registry index at path
.
sourcepub fn hash(
&mut self,
pkg: PackageId,
load: &mut dyn RegistryData
) -> Poll<CargoResult<&str>>
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
.
sourcefn 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,
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
- 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.
sourcefn load_summaries(
&mut self,
name: InternedString,
load: &mut dyn RegistryData
) -> Poll<CargoResult<&mut Summaries>>
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:
-
Returns from in-memory cache, aka
RegistryIndex::summaries_cache
. -
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
theload
argument is given. For example, a Git-basedRemoteRegistry
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.
sourcepub fn clear_summaries_cache(&mut self)
pub fn clear_summaries_cache(&mut self)
Clears the in-memory summaries cache.
sourcepub fn query_inner(
&mut self,
name: InternedString,
req: &OptVersionReq,
load: &mut dyn RegistryData,
yanked_whitelist: &HashSet<PackageId>,
f: &mut dyn FnMut(Summary)
) -> Poll<CargoResult<()>>
pub fn query_inner( &mut self, name: InternedString, req: &OptVersionReq, load: &mut dyn RegistryData, yanked_whitelist: &HashSet<PackageId>, f: &mut dyn FnMut(Summary) ) -> Poll<CargoResult<()>>
Attempts to find the packages that match a name
and a version req
.
This is primarily used by Source::query
.
sourcefn query_inner_with_online(
&mut self,
name: InternedString,
req: &OptVersionReq,
load: &mut dyn RegistryData,
yanked_whitelist: &HashSet<PackageId>,
f: &mut dyn FnMut(IndexSummary),
online: bool
) -> Poll<CargoResult<()>>
fn query_inner_with_online( &mut self, name: InternedString, req: &OptVersionReq, load: &mut dyn RegistryData, yanked_whitelist: &HashSet<PackageId>, 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.
sourcepub fn is_yanked(
&mut self,
pkg: PackageId,
load: &mut dyn RegistryData
) -> Poll<CargoResult<bool>>
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<'cfg> !RefUnwindSafe for RegistryIndex<'cfg>
impl<'cfg> !Send for RegistryIndex<'cfg>
impl<'cfg> !Sync for RegistryIndex<'cfg>
impl<'cfg> Unpin for RegistryIndex<'cfg>
impl<'cfg> !UnwindSafe for RegistryIndex<'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: 88 bytes