JetBrains Space Help

Get Rust Packages

The typical way of getting a Rust package is referencing it in the project dependencies.

  1. Configure connection to the Cargo registry. The instructions are different for a local Cargo registry and for a mirror of a remote registry (the most common case is mirroring crates.io):

    1. In your Rust project, add the config.toml file to the .cargo directory.

    2. Add the registry data to the config.toml file. For example:

      [registries.space-registry] index = "sparse+https://cargo.registry.jetbrains.space/mycompany/p/projectkey/myCrates" credential-provider="cargo:token"

      If you are not sure about the URL, you can copy the URL of a particular container registry on the Packages page.

    3. Log in to the registry:

      cargo login --registry=space-registry

      Here space-registry is the registry name you specified in config.toml.

    4. When asked for credentials, specify either your Space username and password (we recommend that you use a personal token instead) or a client ID and a client secret of a service account.

    1. In your Rust project, add the config.toml file to the .cargo directory.

    2. Add the registry data to the config.toml file. For example:

      [registries.space-registry-mirror] index = "sparse+https://cargo.registry.jetbrains.space/mycompany/p/projectkey/myCrates-mirror" credential-provider="cargo:token"

      If you are not sure about the URL, you can copy the URL of a particular container registry on the Packages page.

    3. Log in to the registry:

      cargo login --registry=space-registry-mirror

      Here space-registry-mirror is the registry name you specified in config.toml.

    4. When asked for credentials, specify either your Space username and password (we recommend that you use a personal token instead) or a client ID and a client secret of a service account.

    5. Open the config.toml and configure registry replacing by adding the lines:

      [source] space-registry-mirror = { registry = "sparse+https://cargo.registry.jetbrains.space/mycompany/p/projectkey/myCrates-mirror" } crates-io = { replace-with = "space-registry-mirror" }
  2. Add the dependency to the project's Cargo.toml file. For example:

    [dependencies] rust-sample-project = { version = "0.1.0", registry = "space-registry" }

    Here rust-sample-project is the package name and space-registry is the registry name you specified in config.toml.

    Note that you can get the exact package reference in Space:

    1. In Space, open the Packages page of the project that provides the required package.

    2. Find the desired package.

    3. Open the package properties page, copy the reference snippet, and paste it to your Cargo.toml.

  3. Build your project with the new dependency:

    cargo build
Last modified: 21 September 2023