Skip to main content

## RegistryData

# Trait RegistryData

Source

    pub trait RegistryData {
        // Required methods
        fn prepare(&self) -> CargoResult<()>;
        fn index_path(&self) -> &Filesystem;
        fn cache_path(&self) -> &Filesystem;
        fn load<'life0, 'life1, 'life2, 'life3, 'async_trait>(
            &'life0 self,
            root: &'life1 Path,
            path: &'life2 Path,
            index_version: Option<&'life3 str>,
        ) -> Pin<Box<dyn Future<Output = CargoResult<LoadResponse>> + 'async_trait>>
           where Self: 'async_trait,
                 'life0: 'async_trait,
                 'life1: 'async_trait,
                 'life2: 'async_trait,
                 'life3: 'async_trait;
        fn config<'life0, 'async_trait>(
            &'life0 self,
        ) -> Pin<Box<dyn Future<Output = CargoResult<Option<RegistryConfig>>> + 'async_trait>>
           where Self: 'async_trait,
                 'life0: 'async_trait;
        fn invalidate_cache(&self);
        fn set_quiet(&mut self, quiet: bool);
        fn is_updated(&self) -> bool;
        fn download<'life0, 'life1, 'async_trait>(
            &'life0 self,
            pkg: PackageId,
            checksum: &'life1 str,
        ) -> Pin<Box<dyn Future<Output = CargoResult<MaybeLock>> + 'async_trait>>
           where Self: 'async_trait,
                 'life0: 'async_trait,
                 'life1: 'async_trait;
        fn finish_download<'life0, 'life1, 'life2, 'async_trait>(
            &'life0 self,
            pkg: PackageId,
            checksum: &'life1 str,
            data: &'life2 [u8],
        ) -> Pin<Box<dyn Future<Output = CargoResult<File>> + 'async_trait>>
           where Self: 'async_trait,
                 'life0: 'async_trait,
                 'life1: 'async_trait,
                 'life2: 'async_trait;
        fn assert_index_locked<'a>(&self, path: &'a Filesystem) -> &'a Path;

        // Provided method
        fn is_crate_downloaded(&self, _pkg: PackageId) -> bool { ... }
    }

Expand description

An abstract interface to handle both a local and remote registry.

This allows `RegistrySource` to abstractly handle each registry kind.

For general concepts of registries, see the module-level documentation.

## Required Methods§

Source

#### fn prepare(&self) -> CargoResult<()>

Performs initialization for the registry.

This should be safe to call multiple times, the implementation is expected to not do any work if it is already prepared.

Source

#### fn index_path(&self) -> &Filesystem

Returns the path to the index.

Note that different registries store the index in different formats (remote = git, http & local = files).

Source

#### fn cache_path(&self) -> &Filesystem

Returns the path of the directory that stores the cache of `.crate` files.

The directory is currently expected to contain a flat list of all `.crate` files, named `<package-name>-<version>.crate`.

Source

#### fn load<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, root: &'life1 Path, path: &'life2 Path, index_version: Option<&'life3 str>, ) -> Pin<Box<dyn Future<Output = CargoResult<LoadResponse>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Loads the JSON for a specific named package from the index.

- `root` is the root path to the index.
- `path` is the relative path to the package to load (like `ca/rg/cargo`).
- `index_version` is the version of the requested crate data currently in cache. This is useful for checking if a local cache is outdated.

Source

#### fn config<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CargoResult<Option<RegistryConfig>>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Loads the `config.json` file and returns it.

Local registries don’t have a config, and return `None`.

Source

#### fn invalidate_cache(&self)

Invalidates locally cached data.

Source

#### fn set_quiet(&mut self, quiet: bool)

If quiet, the source should not display any progress or status messages.

Source

#### fn is_updated(&self) -> bool

Is the local cached data up-to-date?

Source

#### fn download<'life0, 'life1, 'async_trait>( &'life0 self, pkg: PackageId, checksum: &'life1 str, ) -> Pin<Box<dyn Future<Output = CargoResult<MaybeLock>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Prepare to start downloading a `.crate` file.

Despite the name, this doesn’t actually download anything. If the `.crate` is already downloaded, then it returns `MaybeLock::Ready`. If it hasn’t been downloaded, then it returns `MaybeLock::Download` which contains the URL to download. The `crate::core::package::Downloads` system handles the actual download process. After downloading, it calls `Self::finish_download` to save the downloaded file.

`checksum` is currently only used by local registries to verify the file contents (because local registries never actually download anything). Remote registries will validate the checksum in `finish_download`. For already downloaded `.crate` files, it does not validate the checksum, assuming the filesystem does not suffer from corruption or manipulation.

Source

#### fn finish_download<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, pkg: PackageId, checksum: &'life1 str, data: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = CargoResult<File>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Finish a download by saving a `.crate` file to disk.

After `crate::core::package::Downloads` has finished a download, it will call this to save the `.crate` file. This is only relevant for remote registries. This should validate the checksum and save the given data to the on-disk cache.

Returns a `File` handle to the `.crate` file, positioned at the start.

Source

#### fn assert_index_locked<'a>(&self, path: &'a Filesystem) -> &'a Path

Validates that the global package cache lock is held.

Given the `Filesystem`, this will make sure that the package cache lock is held. If not, it will panic. See `GlobalContext::acquire_package_cache_lock` for acquiring the global lock.

Returns the `Path` to the `Filesystem`.

## Provided Methods§

Source

#### fn is_crate_downloaded(&self, _pkg: PackageId) -> bool

Returns whether or not the `.crate` file is already downloaded.

## Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

## Implementors§

Source§

### impl<'gctx> RegistryData for HttpRegistry<'gctx>

Source§

### impl<'gctx> RegistryData for LocalRegistry<'gctx>

Source§

### impl<'gctx> RegistryData for RemoteRegistry<'gctx>