pub struct SparseIndex { /* private fields */ }
Expand description
Wrapper around managing a sparse HTTP index, re-using Cargo’s local disk caches.
Currently it only uses local Cargo cache, and does not access the network in any way.
For examples of how to update the local cache,
see examples/sparse_http_reqwest.rs
and examples/sparse_http_ureq.rs
.
Implementations§
Source§impl SparseIndex
impl SparseIndex
Sourcepub fn from_url(url: &str) -> Result<Self, Error>
pub fn from_url(url: &str) -> Result<Self, Error>
Creates a view over the sparse HTTP index from a provided URL, opening the same location on disk that Cargo uses for that registry index’s metadata and cache.
Note this function takes the CARGO_HOME
environment variable into account
Sourcepub fn new_cargo_default() -> Result<Self, Error>
pub fn new_cargo_default() -> Result<Self, Error>
Creates an index for the default crates.io registry, using the same disk location as Cargo itself.
This is the recommended way to access the crates.io sparse index.
Note this function takes the CARGO_HOME
environment variable into account
Sourcepub fn with_path(
cargo_home: impl AsRef<Path>,
url: impl AsRef<str>,
) -> Result<Self, Error>
pub fn with_path( cargo_home: impl AsRef<Path>, url: impl AsRef<str>, ) -> Result<Self, Error>
Creates a view over the sparse HTTP index from the provided URL, rooted at the specified location
Sourcepub fn at_path(path: PathBuf, url: String) -> Self
pub fn at_path(path: PathBuf, url: String) -> Self
Creates a view over the sparse HTTP index at the exact specified path
Sourcepub fn index_config(&self) -> Result<IndexConfig, Error>
pub fn index_config(&self) -> Result<IndexConfig, Error>
Get the global configuration of the index. There are no guarantees around freshness, and if the config is not available, no fetch will be performed.
Sourcepub fn crate_from_cache(&self, name: &str) -> Result<Crate, Error>
pub fn crate_from_cache(&self, name: &str) -> Result<Crate, Error>
Reads a crate from the local cache of the index. There are no guarantees around freshness, and if the crate is not known in the cache, no fetch will be performed.
Sourcepub fn crate_url(&self, name: &str) -> Option<String>
pub fn crate_url(&self, name: &str) -> Option<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 Crate::from_slice
Sourcepub fn make_config_request(&self) -> Result<Builder, Error>
Available on crate feature sparse
only.
pub fn make_config_request(&self) -> Result<Builder, Error>
sparse
only.Creates an HTTP request that can be sent via your HTTP client of choice to retrieve the config for this index.
See Self::parse_config_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 make_cache_request(&self, name: &str) -> Result<Builder, Error>
Available on crate feature sparse
only.
pub fn make_cache_request(&self, name: &str) -> Result<Builder, Error>
sparse
only.Creates an HTTP request that can be sent via your HTTP client of choice
to retrieve the current metadata for the specified crate namw
.
See Self::parse_cache_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_config_response(
&self,
response: Response<Vec<u8>>,
write_config: bool,
) -> Result<IndexConfig, Error>
Available on crate feature sparse
only.
pub fn parse_config_response( &self, response: Response<Vec<u8>>, write_config: bool, ) -> Result<IndexConfig, Error>
sparse
only.Process the response to a request created by Self::make_config_request()
.
If write_config
is true
, write the configuration to disk after parsing it.
Note that the write operation may fail, and as opposed to the similar parameter
in Self::parse_cache_response()
, write errors will not be ignored.
Note that the response
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.
Sourcepub fn parse_cache_response(
&self,
name: &str,
response: Response<Vec<u8>>,
write_cache_entry: bool,
) -> Result<Option<Crate>, Error>
Available on crate feature sparse
only.
pub fn parse_cache_response( &self, name: &str, response: Response<Vec<u8>>, write_cache_entry: bool, ) -> Result<Option<Crate>, Error>
sparse
only.Process the response to a request created by Self::make_cache_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
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> 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