Loading CHANGELOG.next.toml +6 −0 Original line number Diff line number Diff line Loading @@ -10,3 +10,9 @@ # references = ["smithy-rs#920"] # meta = { "breaking" = false, "tada" = false, "bug" = false } # author = "rcoh" [[smithy-rs]] message = "`DynMiddleware` is now `clone`able" references = ["smithy-rs#1225"] meta = { "breaking" = false, "tada" = false, "bug" = false } author = "Velfi" rust-runtime/aws-smithy-client/src/erase.rs +8 −2 Original line number Diff line number Diff line Loading @@ -187,7 +187,7 @@ impl Service<http::Request<SdkBody>> for DynConnector { /// to matter in all but the highest-performance settings. #[non_exhaustive] pub struct DynMiddleware<C>( BoxCloneLayer< ArcCloneLayer< aws_smithy_http_tower::dispatch::DispatchService<C>, aws_smithy_http::operation::Request, aws_smithy_http::operation::Response, Loading @@ -195,6 +195,12 @@ pub struct DynMiddleware<C>( >, ); impl<C> Clone for DynMiddleware<C> { fn clone(&self) -> Self { Self(self.0.clone()) } } impl<C> fmt::Debug for DynMiddleware<C> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("DynMiddleware").finish() Loading @@ -204,7 +210,7 @@ impl<C> fmt::Debug for DynMiddleware<C> { impl<C> DynMiddleware<C> { /// Construct a new dynamically-dispatched Smithy middleware. pub fn new<M: bounds::SmithyMiddleware<C> + Send + Sync + 'static>(middleware: M) -> Self { Self(BoxCloneLayer::new(middleware)) Self(ArcCloneLayer::new(middleware)) } } Loading rust-runtime/aws-smithy-client/src/erase/boxclone.rs +18 −8 Original line number Diff line number Diff line Loading @@ -9,15 +9,25 @@ use std::fmt; use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; use tower::layer::{layer_fn, Layer}; use tower::Service; pub(super) struct BoxCloneLayer<In, T, U, E> { boxed: Box<dyn Layer<In, Service = BoxCloneService<T, U, E>> + Send + Sync>, pub(super) struct ArcCloneLayer<In, T, U, E> { inner: Arc<dyn Layer<In, Service = BoxCloneService<T, U, E>> + Send + Sync>, } impl<In, T, U, E> Clone for ArcCloneLayer<In, T, U, E> { fn clone(&self) -> Self { Self { inner: self.inner.clone(), } } } impl<In, T, U, E> BoxCloneLayer<In, T, U, E> { impl<In, T, U, E> ArcCloneLayer<In, T, U, E> { /// Create a new [`BoxLayer`]. pub fn new<L>(inner_layer: L) -> Self where Loading @@ -31,22 +41,22 @@ impl<In, T, U, E> BoxCloneLayer<In, T, U, E> { }); Self { boxed: Box::new(layer), inner: Arc::new(layer), } } } impl<In, T, U, E> Layer<In> for BoxCloneLayer<In, T, U, E> { impl<In, T, U, E> Layer<In> for ArcCloneLayer<In, T, U, E> { type Service = BoxCloneService<T, U, E>; fn layer(&self, inner: In) -> Self::Service { self.boxed.layer(inner) self.inner.layer(inner) } } impl<In, T, U, E> fmt::Debug for BoxCloneLayer<In, T, U, E> { impl<In, T, U, E> fmt::Debug for ArcCloneLayer<In, T, U, E> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("BoxCloneLayer").finish() fmt.debug_struct("ArcCloneLayer").finish() } } Loading Loading
CHANGELOG.next.toml +6 −0 Original line number Diff line number Diff line Loading @@ -10,3 +10,9 @@ # references = ["smithy-rs#920"] # meta = { "breaking" = false, "tada" = false, "bug" = false } # author = "rcoh" [[smithy-rs]] message = "`DynMiddleware` is now `clone`able" references = ["smithy-rs#1225"] meta = { "breaking" = false, "tada" = false, "bug" = false } author = "Velfi"
rust-runtime/aws-smithy-client/src/erase.rs +8 −2 Original line number Diff line number Diff line Loading @@ -187,7 +187,7 @@ impl Service<http::Request<SdkBody>> for DynConnector { /// to matter in all but the highest-performance settings. #[non_exhaustive] pub struct DynMiddleware<C>( BoxCloneLayer< ArcCloneLayer< aws_smithy_http_tower::dispatch::DispatchService<C>, aws_smithy_http::operation::Request, aws_smithy_http::operation::Response, Loading @@ -195,6 +195,12 @@ pub struct DynMiddleware<C>( >, ); impl<C> Clone for DynMiddleware<C> { fn clone(&self) -> Self { Self(self.0.clone()) } } impl<C> fmt::Debug for DynMiddleware<C> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("DynMiddleware").finish() Loading @@ -204,7 +210,7 @@ impl<C> fmt::Debug for DynMiddleware<C> { impl<C> DynMiddleware<C> { /// Construct a new dynamically-dispatched Smithy middleware. pub fn new<M: bounds::SmithyMiddleware<C> + Send + Sync + 'static>(middleware: M) -> Self { Self(BoxCloneLayer::new(middleware)) Self(ArcCloneLayer::new(middleware)) } } Loading
rust-runtime/aws-smithy-client/src/erase/boxclone.rs +18 −8 Original line number Diff line number Diff line Loading @@ -9,15 +9,25 @@ use std::fmt; use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; use tower::layer::{layer_fn, Layer}; use tower::Service; pub(super) struct BoxCloneLayer<In, T, U, E> { boxed: Box<dyn Layer<In, Service = BoxCloneService<T, U, E>> + Send + Sync>, pub(super) struct ArcCloneLayer<In, T, U, E> { inner: Arc<dyn Layer<In, Service = BoxCloneService<T, U, E>> + Send + Sync>, } impl<In, T, U, E> Clone for ArcCloneLayer<In, T, U, E> { fn clone(&self) -> Self { Self { inner: self.inner.clone(), } } } impl<In, T, U, E> BoxCloneLayer<In, T, U, E> { impl<In, T, U, E> ArcCloneLayer<In, T, U, E> { /// Create a new [`BoxLayer`]. pub fn new<L>(inner_layer: L) -> Self where Loading @@ -31,22 +41,22 @@ impl<In, T, U, E> BoxCloneLayer<In, T, U, E> { }); Self { boxed: Box::new(layer), inner: Arc::new(layer), } } } impl<In, T, U, E> Layer<In> for BoxCloneLayer<In, T, U, E> { impl<In, T, U, E> Layer<In> for ArcCloneLayer<In, T, U, E> { type Service = BoxCloneService<T, U, E>; fn layer(&self, inner: In) -> Self::Service { self.boxed.layer(inner) self.inner.layer(inner) } } impl<In, T, U, E> fmt::Debug for BoxCloneLayer<In, T, U, E> { impl<In, T, U, E> fmt::Debug for ArcCloneLayer<In, T, U, E> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("BoxCloneLayer").finish() fmt.debug_struct("ArcCloneLayer").finish() } } Loading