Install the Rust SDK

Updated at:

You must add the Alibaba Cloud Simple Log Service (SLS) Rust SDK as a dependency of your Rust project before your project code can call it. This topic describes how to add the aliyun-log-rust-sdk dependency to a new or existing Rust project and how to confirm the result. It does not cover Rust SDK initialization (configuring the service endpoint and access credentials).

Prerequisites

Environment requirements: You must install Rust and Cargo. (Recommended) Use the latest stable Rust toolchain. Run the following commands to check whether the toolchain is installed and to view its version:

rustc --version
cargo --version

Network requirements: The first build downloads dependencies from the Cargo package registry. The build environment must have access to the registry. If it cannot access the registry, the dependency download fails.

The steps in this topic follow one of two paths, depending on your project. To create a new Rust project, start with Step 1 and complete the steps in order. If you already have a Rust project, skip Step 1, go to the directory that contains the project's Cargo.toml, and then start with Step 2.

Step 1: Create a Rust project

Run the following commands to create a Rust project named sls-rust-demo and enter the project directory:

cargo new sls-rust-demo
cd sls-rust-demo

Step 2: Add the Rust SDK dependency

In the directory that contains the project's Cargo.toml, run the following command to add the Rust SDK as a project dependency:

cargo add aliyun-log-rust-sdk

Step 3: Verify the installation

Open the project's Cargo.toml and confirm that the dependency list contains a new aliyun-log-rust-sdk entry. The presence of this entry indicates that the Rust SDK is installed.

Important

If the dependency download fails, check whether the build environment can access the Cargo package registry.

What to do next

After you add the dependency, see the Initialize the Rust SDK topic to configure the service endpoint and access credentials.