Unverified Commit 9708aa83 authored by Jacco Kulman's avatar Jacco Kulman Committed by GitHub
Browse files

Clone-able structs (#985)



* Clone-able structs

* Change log entry

* Update CHANGELOG.next.toml

Co-authored-by: default avatarRussell Cohen <russell.r.cohen@gmail.com>

* Added two Clone directives and integration test

Co-authored-by: default avatarRussell Cohen <russell.r.cohen@gmail.com>
Co-authored-by: default avatarRussell Cohen <rcoh@amazon.com>
parent 1992bf3f
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -11,6 +11,18 @@
# meta = { "breaking" = false, "tada" = false, "bug" = false }
# author = "rcoh"

[[smithy-rs]]
message = "Made fluent operation structs cloneable"
references = ["aws-sdk-rust#254"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "Jacco"

[[aws-sdk-rust]]
message = "Made fluent operation structs cloneable"
references = ["aws-sdk-rust#254"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "Jacco"

[[aws-sdk-rust]]
message = "Codegen will no longer produce builders and clients with methods that take `impl Into<T>` except for strings and boxed types."
meta = { "breaking" = true, "tada" = false, "bug" = false }
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ type DefaultMiddlewareStack = Stack<
/// 2. Sign the request with SigV4
/// 3. Resolve an Endpoint for the request
/// 4. Add a user agent to the request
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
pub struct DefaultMiddleware;

+35 −0
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

use aws_types::credentials::SharedCredentialsProvider;
use aws_types::region::Region;
use aws_types::Credentials;

// compiling this function validates that fluent builders are cloneable
#[allow(dead_code)]
async fn ensure_builders_clone() {
    let shared_config = aws_types::config::Config::builder()
        .region(Region::new("us-east-4"))
        .credentials_provider(SharedCredentialsProvider::new(Credentials::new(
            "asdf", "asdf", None, None, "test",
        )))
        .build();
    let client = aws_sdk_dynamodb::Client::new(&shared_config);
    let base_query = client.list_tables();
    let mut tables = vec![];
    for i in 0..100 {
        let query = base_query
            .clone()
            .exclusive_start_table_name(format!("table-{}", i));
        tables.extend(
            query
                .send()
                .await
                .expect("failed")
                .table_names
                .unwrap_or_default(),
        );
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import software.amazon.smithy.rust.codegen.smithy.customize.NamedSectionGenerato
import software.amazon.smithy.rust.codegen.smithy.customize.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.smithy.customize.Section
import software.amazon.smithy.rust.codegen.smithy.customize.writeCustomizations
import software.amazon.smithy.rust.codegen.smithy.expectRustMetadata
import software.amazon.smithy.rust.codegen.smithy.generators.error.errorSymbol
import software.amazon.smithy.rust.codegen.smithy.rustType
import software.amazon.smithy.rust.codegen.util.inputShape
@@ -394,7 +395,8 @@ class FluentClientGenerator(
                val operationSymbol = symbolProvider.toSymbol(operation)
                val input = operation.inputShape(model)
                val members: List<MemberShape> = input.allMembers.values.toList()

                val baseDerives = symbolProvider.toSymbol(input).expectRustMetadata().derives
                val derives = baseDerives.derives.intersect(setOf(RuntimeType.Clone)) + RuntimeType.Debug
                rust(
                    """
                    /// Fluent builder constructing a request to `${operationSymbol.name}`.
@@ -402,9 +404,9 @@ class FluentClientGenerator(
                    """
                )
                documentShape(operation, model, autoSuppressMissingDocs = false)
                baseDerives.copy(derives = derives).render(this)
                rustTemplate(
                    """
                    ##[derive(std::fmt::Debug)]
                    pub struct ${operationSymbol.name}#{generics:W} {
                        handle: std::sync::Arc<super::Handle${generics.inst}>,
                        inner: #{Inner}
+1 −1
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ const RETRY_COST: usize = 5;
/// `CrossRequestRetryState`
/// Its main functionality is via `new_request_policy` which creates a `RetryHandler` to manage the retry for
/// an individual request.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Standard {
    config: Config,
    shared_state: CrossRequestRetryState,