fun render()

in aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt [106:164]


    fun render(writer: RustWriter) {
        writer.rustBlockTemplate("impl<C> Client<C, #{Middleware}, #{retry}::Standard>", *codegenScope) {
            rustTemplate(
                """
                /// Creates a client with the given service config and connector override.
                pub fn from_conf_conn(conf: crate::Config, conn: C) -> Self {
                    let retry_config = conf.retry_config.as_ref().cloned().unwrap_or_default();
                    let timeout_config = conf.timeout_config.as_ref().cloned().unwrap_or_default();
                    let sleep_impl = conf.sleep_impl.clone();
                    let mut builder = #{aws_smithy_client}::Builder::new()
                        .connector(conn)
                        .middleware(#{Middleware}::new());
                    builder.set_retry_config(retry_config.into());
                    builder.set_timeout_config(timeout_config);
                    if let Some(sleep_impl) = sleep_impl {
                        builder.set_sleep_impl(Some(sleep_impl));
                    }
                    let client = builder.build();
                    Self { handle: std::sync::Arc::new(Handle { client, conf }) }
                }
                """,
                *codegenScope
            )
        }
        writer.rustBlockTemplate("impl Client<#{DynConnector}, #{Middleware}, #{retry}::Standard>", *codegenScope) {
            rustTemplate(
                """
                /// Creates a new client from a shared config.
                ##[cfg(any(feature = "rustls", feature = "native-tls"))]
                pub fn new(config: &#{aws_types}::config::Config) -> Self {
                    Self::from_conf(config.into())
                }

                /// Creates a new client from the service [`Config`](crate::Config).
                ##[cfg(any(feature = "rustls", feature = "native-tls"))]
                pub fn from_conf(conf: crate::Config) -> Self {
                    let retry_config = conf.retry_config.as_ref().cloned().unwrap_or_default();
                    let timeout_config = conf.timeout_config.as_ref().cloned().unwrap_or_default();
                    let sleep_impl = conf.sleep_impl.clone();
                    let mut builder = #{aws_smithy_client}::Builder::dyn_https()
                        .middleware(#{Middleware}::new());
                    builder.set_retry_config(retry_config.into());
                    builder.set_timeout_config(timeout_config);
                    // the builder maintains a try-state. To avoid suppressing the warning when sleep is unset,
                    // only set it if we actually have a sleep impl.
                    if let Some(sleep_impl) = sleep_impl {
                        builder.set_sleep_impl(Some(sleep_impl));
                    }
                    let client = builder.build();

                    Self { handle: std::sync::Arc::new(Handle { client, conf }) }
                }
                """,
                "aws_smithy_client" to types.awsSmithyClient,
                "aws_types" to types.awsTypes,
                "Middleware" to types.defaultMiddleware
            )
        }
    }