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

source

pub fn new(il: IndexLocation<'_>) -> Result<Self, Error>

Creates a new sparse index for the specified location

source

pub fn index_config(&self) -> Result<IndexConfig, Error>

Get the configuration of the index.

See the cargo docs

source

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

source

pub fn url(&self) -> &str

The HTTP url of the index

source

pub fn cache(&self) -> &IndexCache

Gets the accessor to the local index cache

source

pub fn cached_krate( &self, name: KrateName<'_>, lock: &FileLock ) -> Result<Option<IndexKrate>, Error>

Attempts to read the locally cached crate information

source

pub fn make_remote_request( &self, name: KrateName<'_>, etag: Option<&str>, lock: &FileLock ) -> Result<Request<&'static [u8]>, 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

source

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

source§

fn from(si: SparseIndex) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

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.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

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.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more