Skip to content

Commit

Permalink
Fix debug bound on 0.55.x (#2630)
Browse files Browse the repository at this point in the history
## Motivation and Context
- #2577 added a `Debug` bound on `ResolveEndpoint`, but this was a
semver-incompatible change

## Description
This removes that bound but re-adds a Debug implementation in areas that
we need them

## Testing
- CI

- [ ] Backport this commit to main

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
rcoh authored Apr 25, 2023
1 parent 616cd77 commit 0c5295e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() }")
Expand Down
14 changes: 10 additions & 4 deletions rust-runtime/aws-smithy-http/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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)
}
Expand Down

0 comments on commit 0c5295e

Please sign in to comment.