Unverified Commit f7265aeb authored by ysaito1001's avatar ysaito1001 Committed by GitHub
Browse files

Port fix for debug bound on ResolveEndpoint (#2636)

## Motivation and Context
Port https://github.com/awslabs/smithy-rs/pull/2630 to the `main`
branch.

## Description
Adding `Debug` bound on `ResolveEndpoint` in
https://github.com/awslabs/smithy-rs/pull/2577

 was a breaking change.
Unfortunately, the semvar check that ran in that PR barked at a
different thing (i.e. barked at moving `StaticUriEndpointResolver` and
`DefaultEndpointResolver` from `aws-smithy-runtime-api` to
`aws-smithy-runtime`). Eventually the breaking change got merged to the
`main` branch.

This PR reverts the change in question and implements the `Debug` trait
for `ResolveEndpoint` in a semvar non-breaking way.

## Testing
- [ ] Passed tests in CI

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

Co-authored-by: default avatarYuki Saito <awsaito@amazon.com>
parent d7297599
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -228,12 +228,25 @@ class ServiceConfigGenerator(private val customizations: List<ConfigCustomizatio
        }

        writer.docs("Builder for creating a `Config`.")
        writer.raw("#[derive(Clone, Debug, Default)]")
        writer.raw("#[derive(Clone, Default)]")
        writer.rustBlock("pub struct Builder") {
            customizations.forEach {
                it.section(ServiceConfig.BuilderStruct)(this)
            }
        }

        // Custom implementation for Debug so we don't need to enforce Debug down the chain
        writer.rustBlock("impl std::fmt::Debug for Builder") {
            writer.rustTemplate(
                """
                fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                    let mut config = f.debug_struct("Builder");
                    config.finish()
                }
                """,
            )
        }

        writer.rustBlock("impl Builder") {
            writer.docs("Constructs a config builder.")
            writer.rustTemplate("pub fn new() -> Self { Self::default() }")
+10 −4
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ use crate::endpoint::error::InvalidEndpointError;
use crate::operation::error::BuildError;
use http::uri::{Authority, Uri};
use std::borrow::Cow;
use std::fmt::Debug;
use std::fmt::{Debug, Formatter};
use std::result::Result as StdResult;
use std::str::FromStr;
use std::sync::Arc;
@@ -23,7 +23,7 @@ pub use error::ResolveEndpointError;
pub type Result = std::result::Result<aws_smithy_types::endpoint::Endpoint, ResolveEndpointError>;

/// Implementors of this trait can resolve an endpoint that will be applied to a request.
pub trait ResolveEndpoint<Params>: Debug + Send + Sync {
pub trait ResolveEndpoint<Params>: Send + Sync {
    /// Given some endpoint parameters, resolve an endpoint or return an error when resolution is
    /// impossible.
    fn resolve_endpoint(&self, params: &Params) -> Result;
@@ -38,9 +38,15 @@ impl<T> ResolveEndpoint<T> for &'static str {
}

/// Endpoint Resolver wrapper that may be shared
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct SharedEndpointResolver<T>(Arc<dyn ResolveEndpoint<T>>);

impl<T> Debug for SharedEndpointResolver<T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("SharedEndpointResolver").finish()
    }
}

impl<T> SharedEndpointResolver<T> {
    /// Create a new `SharedEndpointResolver` from `ResolveEndpoint`
    pub fn new(resolve_endpoint: impl ResolveEndpoint<T> + 'static) -> Self {
@@ -60,7 +66,7 @@ impl<T> From<Arc<dyn ResolveEndpoint<T>>> for SharedEndpointResolver<T> {
    }
}

impl<T: Debug> ResolveEndpoint<T> for SharedEndpointResolver<T> {
impl<T> ResolveEndpoint<T> for SharedEndpointResolver<T> {
    fn resolve_endpoint(&self, params: &T) -> Result {
        self.0.resolve_endpoint(params)
    }