Struct cargo::sources::registry::index::cache::SummariesCache

source ·
pub struct SummariesCache<'a> {
    pub versions: Vec<(Version, &'a [u8])>,
    pub index_version: &'a str,
}
Expand description

A representation of the cache on disk that Cargo maintains of summaries.

Cargo will initially parse all summaries in the registry and will then serialize that into this form and place it in a new location on disk, ensuring that access in the future is much speedier.

For serialization and deserialization of this on-disk index cache of summaries, see SummariesCache::serialize and SummariesCache::parse.

§The format of the index cache

The idea of this format is that it’s a very easy file for Cargo to parse in future invocations. The read from disk should be fast and then afterwards all we need to know is what versions correspond to which JSON blob.

Currently the format looks like:

+---------------+----------------------+--------------------+---+
| cache version | index schema version | index file version | 0 |
+---------------+----------------------+--------------------+---+

followed by one or more (version + JSON blob) pairs…

+----------------+---+-----------+---+
| semver version | 0 | JSON blob | 0 | ...
+----------------+---+-----------+---+

Each field represents:

  • cache version — Intended to ensure that there’s some level of future compatibility against changes to this cache format so if different versions of Cargo share the same cache they don’t get too confused.
  • index schema version — The schema version of the raw index file. See IndexPackage::v for the detail.
  • index file version — Tracks when a cache needs to be regenerated. A cache regeneration is required whenever the index file itself updates.
  • semver version — The version for each JSON blob. Extracted from the blob for fast queries without parsing the entire blob.
  • JSON blob — The actual metadata for each version of the package. It has the same representation as IndexPackage.

§Changes between each cache version

  • 1: The original version.
  • 2: Added the “index schema version” field so that if the index schema changes, different versions of cargo won’t get confused reading each other’s caches.
  • 3: Bumped the version to work around an issue where multiple versions of a package were published that differ only by semver metadata. For example, openssl-src 110.0.0 and 110.0.0+1.1.0f. Previously, the cache would be incorrectly populated with two entries, both 110.0.0. After this, the metadata will be correctly included. This isn’t really a format change, just a version bump to clear the incorrect cache entries. Note: the index shouldn’t allow these, but unfortunately crates.io doesn’t check it.

See CURRENT_CACHE_VERSION for the current cache version.

Fields§

§versions: Vec<(Version, &'a [u8])>

JSON blobs of the summaries. Each JSON blob has a Version beside, so that Cargo can query a version without full JSON parsing.

§index_version: &'a str

For cache invalidation, we tracks the index file version to determine when to regenerate the cache itself.

Implementations§

source§

impl<'a> SummariesCache<'a>

source

pub fn parse(data: &'a [u8]) -> CargoResult<SummariesCache<'a>>

Deserializes an on-disk cache.

source

pub fn serialize(&self, index_version: &str) -> Vec<u8>

Serializes itself with a given index_version.

Trait Implementations§

source§

impl<'a> Default for SummariesCache<'a>

source§

fn default() -> SummariesCache<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SummariesCache<'a>

§

impl<'a> RefUnwindSafe for SummariesCache<'a>

§

impl<'a> Send for SummariesCache<'a>

§

impl<'a> Sync for SummariesCache<'a>

§

impl<'a> Unpin for SummariesCache<'a>

§

impl<'a> UnwindSafe for SummariesCache<'a>

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.

§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 40 bytes