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.

Implementations§

source§

impl Index

source

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

source

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

source

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

source

pub fn at_path(path: PathBuf, url: String) -> Self

Creates a view over the sparse HTTP index at the exact specified path

source

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

Get the global configuration of the index.

source

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.

source

pub fn url(&self) -> &str

The HTTP url of the index

source

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

source

pub fn make_cache_request(&self, name: &str) -> 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

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

source

pub fn parse_cache_response( &self, name: &str, response: Response<Vec<u8>>, write_cache_entry: bool ) -> Result<Option<Crate>, Error>

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 RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnwindSafe for Index

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.