Setting up your development environment
Prepare your environment for Rust app development and deployment on Google Cloud by installing the following tools.
Install Rust
-
To install Rust, see Getting Started.
-
Confirm that you have the most recent version of Rust installed:
cargo --version
Install an editor
The Getting Started guide links popular editor plugins and IDEs, which provide the following features:
- Fully integrated debugging capabilities
- Syntax highlighting
- Code completion
Install the Google Cloud CLI
The Google Cloud CLI is a set of tools for Google Cloud. It contains the
gcloud
and bq
command-line tools used to access Compute Engine, Cloud Storage,
BigQuery, and other services from the command line. You can run these
tools interactively or in your automated scripts.
To install the gcloud CLI, see Installing the gcloud CLI.
Install the Cloud Client Libraries for Rust in a New Project
The [Cloud Client Libraries for Rust] is the idiomatic way for Rust developers to integrate with Google Cloud services, such as Secret Manager and Workflows.
For example, to use the package for an individual API, such as the Secret Manager API, do the following:
-
Create a new Rust project:
cargo new my-project
-
Change your directory to the new project:
cd my-project
-
Add the [Secret Manager] client library to the new project
cargo add google-cloud-secretmanager-v1
-
Add the tokio crate to the new project
cargo add tokio --features macros
-
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(())
}
-
Build your program:
cargo build
The program should build without errors.
Note: The source of the Cloud Client Libraries for Rust is on GitHub.
Running the program
-
To use the Cloud Client Libraries in a local development environment, set up Application Default Credentials.
gcloud auth application-default login
For more information, see Authenticate for using client libraries.
-
Run your program, replacing
[PROJECT ID]
with the id of your project:cargo run [PROJECT ID]
What's next
- Explore authentication methods at Google.
- Browse the documentation for Google Cloud products.