Skip to content

Port fix for debug bound on ResolveEndpoint #2636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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