Setting up Rust on Cloud Shell

Cloud Shell is a great environment to run small examples and tests.

Start up Cloud Shell

  1. Open https://shell.cloud.google.com to start a new shell.

  2. Select a project.

Configure Rust

  1. Cloud Shell comes with rustup pre-installed. You can use it to install and configure the default version of Rust:

    rustup default stable
  2. Confirm that you have the most recent version of Rust installed:

    cargo --version

Install Rust client libraries in Cloud Shell

  1. Create a new Rust project:

    cargo new my-project
  2. Change your directory to the new project:

    cd my-project
  3. Add the [Secret Manager] client library to the new project

    cargo add google-cloud-secretmanager-v1
  4. Add the tokio crate to the new project

    cargo add tokio --features macros
  5. Edit src/main.rs in your project to use the Secret Manager client library:

#[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { use google_cloud_secretmanager_v1::client::SecretManagerService; let project_id = std::env::args().nth(1).unwrap(); let client = SecretManagerService::new().await?; let mut items = client .list_secrets(format!("projects/{project_id}")) .paginator() .await .items(); while let Some(item) = items.next().await { println!("{}", item?.name); } Ok(()) }
  1. Run your program, replacing [PROJECT ID] with the id of your project:

    cargo run [PROJECT ID]