crates_index

Struct GitIndex

Source
pub struct GitIndex { /* private fields */ }
Available on crate feature git only.
Expand description

Wrapper around managing the crates.io-index git repository

Uses a “bare” git index that fetches files directly from the repo instead of local checkout. Uses Cargo’s cache.

§Instantiation

When creating an instance of this type, the crates-index will be cloned automatically should it not be present. If a repository is present at the location but the remote doesn’t match the desired index URL, a new remote will be added and fetched from.

Please note that concurrent calls to GitIndex::new_cargo_default() (and related) will automatically block and wait for each other, so only one instance will try to clone the index while the others will wait for completion.

This, however, only protects from itself and cargo cloning the index at the same time might interfere.

Implementations§

Source§

impl GitIndex

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 Cargo’s index. *Note that this clones a new index if none is present yet.

Note this function takes the CARGO_HOME environment variable into account

§Concurrency

Concurrent invocations may fail if the index needs to be cloned. To prevent that, use synchronization mechanisms like mutexes or file locks as needed by the application.

Source

pub fn try_new_cargo_default() -> Result<Option<Self>, Error>

Like Self::new_cargo_default(), but read-only without auto-cloning the cargo default git index.

Source

pub fn from_url(url: &str) -> Result<Self, Error>

Creates a bare index from a provided URL, opening the same location on disk that Cargo uses for that registry index.

*Note that this clones a new index if none is present yet.

It can be used to access custom registries.

§Concurrency

Concurrent invocations may fail if the index needs to be cloned. To prevent that, use synchronization mechanisms like mutexes or file locks as needed by the application.

Source

pub fn try_from_url(url: &str) -> Result<Option<Self>, Error>

Like Self::from_url(), but read-only without auto-cloning the index at url.

Source

pub fn with_path<P: Into<PathBuf>, S: Into<String>>( path: P, url: S, ) -> Result<Self, Error>

Creates a bare index at the provided path with the specified repository URL.

*Note that this clones a new index to path if none is present there yet.

§Concurrency

Concurrent invocations may fail if the index needs to be cloned. To prevent that, use synchronization mechanisms like mutexes or file locks as needed by the application.

Source

pub fn try_with_path<P: Into<PathBuf>, S: Into<String>>( path: P, url: S, ) -> Result<Option<Self>, Error>

Like Self::with_path(), but read-only without auto-cloning the index at url if it’s not already present at path.

Source

pub fn path(&self) -> &Path

Get the index directory.

Source

pub fn url(&self) -> &str

Get the index url.

Source

pub fn changes(&self) -> Result<Changes<'_>, Error>

List crates that have changed (published or yanked), in reverse chronological order.

This iterator is aware of periodic index squashing crates.io performs, and will perform (slow and blocking) network requests to fetch the additional history from https://github.com/rust-lang/crates.io-index-archive if needed.

If you want to track newly added/changed crates over time, make a note of the last commit or timestamp you’ve processed, and stop iteration on it next time.

Crates will be reported multiple times, once for each publish/yank/unyank event that happened.

If you like to know publication dates of all crates, consider https://crates.io/data-access instead.

Source

pub fn update(&mut self) -> Result<(), Error>

Fetches latest from the remote index repository. Note that using this method will mean no cache entries will be used, if a new commit is fetched from the repository, as their commit version will no longer match.

Source

pub fn crate_(&self, name: &str) -> Option<Crate>

Reads a crate from the index, it will attempt to use a cached entry if one is available, otherwise it will fallback to reading the crate directly from the git blob containing the crate information.

Use this only if you need to get very few crates. If you’re going to read majority of crates, prefer the GitIndex::crates() iterator.

Source

pub fn crates(&self) -> Crates<'_>

Single-threaded iterator over all the crates in the index.

GitIndex::crates_parallel is typically 4 times faster.

Skips crates that can not be parsed (but there shouldn’t be any such crates in the crates-io index). Also consider to enable git-index-performance feature toggle for better performance.

Source

pub fn crates_parallel( &self, ) -> impl ParallelIterator<Item = Result<Crate, CratesIterError>> + '_

Available on crate feature parallel only.

Iterate over all crates using rayon.

This method is available only if the “parallel” feature is enabled. Also consider to enable git-index-performance feature toggle for better performance.

Source

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

Get the global configuration of the index.

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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.