From b4ec8f64e7b5db66f9c2735971adf92675a09d08 Mon Sep 17 00:00:00 2001 From: David Souther Date: Thu, 2 Nov 2023 11:33:14 -0400 Subject: [PATCH 1/2] Rust: Add proper hello-world for Aurora Closes: #4656 --- .doc_gen/metadata/aurora_metadata.yaml | 4 +- .../examples/aurora/src/bin/hello-world.rs | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 rust_dev_preview/examples/aurora/src/bin/hello-world.rs diff --git a/.doc_gen/metadata/aurora_metadata.yaml b/.doc_gen/metadata/aurora_metadata.yaml index 62a8e0facb8..cb52ab784ac 100644 --- a/.doc_gen/metadata/aurora_metadata.yaml +++ b/.doc_gen/metadata/aurora_metadata.yaml @@ -40,9 +40,7 @@ aurora_Hello: github: rust_dev_preview/examples/aurora excerpts: - snippet_tags: - - rust.aurora.get_cluster.usage - - rust.aurora.describe_db_clusters.wrapper - - rust.aurora.get_cluster.test + - rust.aurora.hello-world services: aurora: {DescribeDBClusters} aurora_DescribeDBClusterParameterGroups: diff --git a/rust_dev_preview/examples/aurora/src/bin/hello-world.rs b/rust_dev_preview/examples/aurora/src/bin/hello-world.rs new file mode 100644 index 00000000000..1852982e384 --- /dev/null +++ b/rust_dev_preview/examples/aurora/src/bin/hello-world.rs @@ -0,0 +1,44 @@ +use std::fmt::Display; + +use aws_sdk_rds::Client; + +#[derive(Debug)] +struct Error(String); +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} +impl std::error::Error for Error {} + +// snippet-start:[rust.aurora.hello-world] +#[tokio::main] +async fn main() -> Result<(), Error> { + tracing_subscriber::fmt::init(); + let sdk_config = aws_config::from_env().load().await; + let client = Client::new(&sdk_config); + + let describe_db_clusters_output = client + .describe_db_clusters() + .send() + .await + .map_err(|e| Error(e.to_string()))?; + println!( + "Found {} clusters:", + describe_db_clusters_output.db_clusters().len() + ); + for cluster in describe_db_clusters_output.db_clusters() { + let name = cluster.database_name().unwrap_or("Unknown"); + let engine = cluster.engine().unwrap_or("Unknown"); + let id = cluster.db_cluster_identifier().unwrap_or("Unknown"); + let class = cluster.db_cluster_instance_class().unwrap_or("Unknown"); + println!("\tDatabase: {name}",); + println!("\t Engine: {engine}",); + println!("\t ID: {id}",); + println!("\tInstance: {class}",); + } + + Ok(()) +} + +// snippet-end:[rust.aurora.hello-world] From 27786ce5befef66230b570a680d5af7c8fadb5f8 Mon Sep 17 00:00:00 2001 From: David Souther Date: Thu, 2 Nov 2023 20:21:01 -0400 Subject: [PATCH 2/2] Use entire example for aurora hellp_world --- .doc_gen/metadata/aurora_metadata.yaml | 4 ++-- rust_dev_preview/examples/aurora/src/bin/hello-world.rs | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.doc_gen/metadata/aurora_metadata.yaml b/.doc_gen/metadata/aurora_metadata.yaml index cb52ab784ac..0014407b09b 100644 --- a/.doc_gen/metadata/aurora_metadata.yaml +++ b/.doc_gen/metadata/aurora_metadata.yaml @@ -39,8 +39,8 @@ aurora_Hello: - sdk_version: 1 github: rust_dev_preview/examples/aurora excerpts: - - snippet_tags: - - rust.aurora.hello-world + - snippet_files: + - rust_dev_preview/examples/aurora/src/bin/hello-world.rs services: aurora: {DescribeDBClusters} aurora_DescribeDBClusterParameterGroups: diff --git a/rust_dev_preview/examples/aurora/src/bin/hello-world.rs b/rust_dev_preview/examples/aurora/src/bin/hello-world.rs index 1852982e384..15999ea1f15 100644 --- a/rust_dev_preview/examples/aurora/src/bin/hello-world.rs +++ b/rust_dev_preview/examples/aurora/src/bin/hello-world.rs @@ -1,17 +1,14 @@ -use std::fmt::Display; - use aws_sdk_rds::Client; #[derive(Debug)] struct Error(String); -impl Display for Error { +impl std::fmt::Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } } impl std::error::Error for Error {} -// snippet-start:[rust.aurora.hello-world] #[tokio::main] async fn main() -> Result<(), Error> { tracing_subscriber::fmt::init(); @@ -40,5 +37,3 @@ async fn main() -> Result<(), Error> { Ok(()) } - -// snippet-end:[rust.aurora.hello-world]