pub struct SparseIndex { /* private fields */ }
Expand description
Wrapper around managing a sparse HTTP index, re-using Cargo’s local disk caches.
This implementation does no network I/O at all. If you want to make requests
to the remote index you may use the Self::make_remote_request
and
Self::parse_remote_response
methods, or you can enable the sparse
feature
and and use RemoteSparseIndex
or
AsyncRemoteSparseIndex
Implementations§
Source§impl SparseIndex
impl SparseIndex
Sourcepub fn new(il: IndexLocation<'_>) -> Result<Self, Error>
pub fn new(il: IndexLocation<'_>) -> Result<Self, Error>
Creates a new sparse index for the specified location
Sourcepub fn index_config(&self) -> Result<IndexConfig, Error>
pub fn index_config(&self) -> Result<IndexConfig, Error>
Get the configuration of the index.
See the cargo docs
Sourcepub fn crate_url(&self, name: KrateName<'_>) -> String
pub fn crate_url(&self, name: KrateName<'_>) -> String
Get the URL that can be used to fetch the index entry for the specified crate
The body of a successful response for the returned URL can be parsed
via IndexKrate::from_slice
See Self::make_remote_request
for a way to make a complete request
Sourcepub fn cache(&self) -> &IndexCache
pub fn cache(&self) -> &IndexCache
Gets the accessor to the local index cache
Sourcepub fn cached_krate(
&self,
name: KrateName<'_>,
lock: &FileLock,
) -> Result<Option<IndexKrate>, Error>
pub fn cached_krate( &self, name: KrateName<'_>, lock: &FileLock, ) -> Result<Option<IndexKrate>, Error>
Attempts to read the locally cached crate information
Sourcepub fn make_remote_request(
&self,
name: KrateName<'_>,
etag: Option<&str>,
lock: &FileLock,
) -> Result<Request<()>, Error>
pub fn make_remote_request( &self, name: KrateName<'_>, etag: Option<&str>, lock: &FileLock, ) -> Result<Request<()>, Error>
Creates an HTTP request that can be sent via your HTTP client of choice to retrieve the current metadata for the specified crate
If specified, the etag is used instead of the possible etag stored in a local cache entry, resulting in no disk I/O being performed by this method
See Self::parse_remote_response
processing the response from the remote
index
It is highly recommended to assume HTTP/2 when making requests to remote indices, at least crates.io
Sourcepub fn parse_remote_response(
&self,
name: KrateName<'_>,
response: Response<Vec<u8>>,
write_cache_entry: bool,
lock: &FileLock,
) -> Result<Option<IndexKrate>, Error>
pub fn parse_remote_response( &self, name: KrateName<'_>, response: Response<Vec<u8>>, write_cache_entry: bool, lock: &FileLock, ) -> Result<Option<IndexKrate>, Error>
Process the response to a request created by Self::make_remote_request
This handles both the scenario where the local cache is missing the specified crate, or it is out of date, as well as the local entry being up to date and can just be read from disk
You may specify whether an updated index entry is written locally to the cache or not
Note that responses from sparse HTTP indices, at least crates.io, may
send responses with gzip
compression, it is your responsibility to
decompress it before sending to this function
Trait Implementations§
Source§impl From<SparseIndex> for ComboIndexCache
impl From<SparseIndex> for ComboIndexCache
Source§fn from(si: SparseIndex) -> Self
fn from(si: SparseIndex) -> Self
Auto Trait Implementations§
impl Freeze for SparseIndex
impl RefUnwindSafe for SparseIndex
impl Send for SparseIndex
impl Sync for SparseIndex
impl Unpin for SparseIndex
impl UnwindSafe for SparseIndex
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> 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