Edit

Share via


Install Azure SDK for Rust crates

The Azure SDK for Rust lets you access Azure services in your Rust projects by installing individual SDK crates with Cargo. This article shows how to install, update, and manage Azure SDK for Rust crates, so you can add only the features you need and keep your projects up to date.

Prerequisites to develop with crates

Tip

For the best development experience, ensure you have the latest stable version of Rust installed.

Install the latest Azure SDK crate version

Get Azure SDK crates from crates.io. Install the individual crates that you need.

cargo add <crate_name>

Replace <crate_name> with the name of the Azure crate you want to install. For example, to install the Azure Identity and Key Vault secrets crates:

cargo add azure_identity azure_security_keyvault_secrets

You can find available crate names in the crate index for Azure.

Install a specific Azure SDK crate version

Sometimes you need to install a particular version of a crate for compatibility testing or to maintain consistency across environments. When you specify a version, you pin your dependency. Your project continues using that version and doesn't automatically receive major or minor updates, but it can still receive patch updates. While pinning can be useful in certain scenarios, we recommend using the latest version to benefit from ongoing improvements and security updates.

cargo add <crate_name>@<version_number>

For example:

cargo add azure_storage_blob@0.20.0

You can also specify version requirements in your Cargo.toml file. For more information on version requirement syntax, see the Rust documentation.

Update Azure SDK crates

To update all crates to their latest compatible versions, run:

cargo update

To update a specific crate, run:

cargo update <crate_name>

Remove a specific Azure SDK crate

To remove a crate from your project, including the Cargo.toml file, run:

cargo remove <crate_name>

Build the project to update your Cargo.lock file:

cargo build

Configure Azure SDK crate features

The azure_core crate provides features for all Azure SDK crates, such as:

  • reqwest: HTTP client implementation.
  • tokio: Async runtime support.

Enable SDK features when adding a crate:

cargo add <crate_name> --features <feature_name_1>,<feature_name_2>

Or specify features in your Cargo.toml:

[dependencies]
<crate_name> = { version = "0.17", features = ["<feature_name_1>", "<feature_name_2>"] }

Additional resources