From 55356a34da66d506637218737167b93ed40d595c Mon Sep 17 00:00:00 2001 From: Fangdun Tsai Date: Mon, 1 Jan 2024 00:27:35 +0800 Subject: [PATCH] fix: make Cloneable pub crate --- viz-core/src/handler.rs | 1 - viz-core/src/handler/boxed.rs | 13 ++++++++++++- viz-core/src/handler/cloneable.rs | 4 ++-- viz-core/src/handler/try_handler.rs | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/viz-core/src/handler.rs b/viz-core/src/handler.rs index 0e47e418..9f4ca452 100644 --- a/viz-core/src/handler.rs +++ b/viz-core/src/handler.rs @@ -3,7 +3,6 @@ use crate::{BoxFuture, Future}; mod cloneable; -pub use cloneable::{BoxCloneable, Cloneable}; mod after; pub use after::After; diff --git a/viz-core/src/handler/boxed.rs b/viz-core/src/handler/boxed.rs index 14531d56..b3fbaca3 100644 --- a/viz-core/src/handler/boxed.rs +++ b/viz-core/src/handler/boxed.rs @@ -1,8 +1,13 @@ -use crate::{handler::BoxCloneable, BoxFuture, Handler, Request, Response, Result}; +use std::fmt; +use super::cloneable::BoxCloneable; +use crate::{BoxFuture, Handler, Request, Response, Result}; + +/// A [`Clone`] + [`Send`] boxed [`Handler`]. pub struct BoxHandler>(BoxCloneable); impl BoxHandler { + /// Creates a new `BoxHandler`. pub fn new(h: H) -> Self where H: Handler + Send + Clone + 'static, @@ -30,3 +35,9 @@ impl From> for BoxHandler { Self(value) } } + +impl fmt::Debug for BoxHandler { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("BoxHandler").finish() + } +} diff --git a/viz-core/src/handler/cloneable.rs b/viz-core/src/handler/cloneable.rs index 7a64744a..6fb448e1 100644 --- a/viz-core/src/handler/cloneable.rs +++ b/viz-core/src/handler/cloneable.rs @@ -1,8 +1,8 @@ use super::Handler; -pub type BoxCloneable = Box + Send>; +pub(crate) type BoxCloneable = Box + Send>; -pub trait Cloneable: Handler { +pub(crate) trait Cloneable: Handler { fn clone_box(&self) -> BoxCloneable; } diff --git a/viz-core/src/handler/try_handler.rs b/viz-core/src/handler/try_handler.rs index 109e9c89..4a2edd87 100644 --- a/viz-core/src/handler/try_handler.rs +++ b/viz-core/src/handler/try_handler.rs @@ -21,4 +21,4 @@ where } } -pub trait TryHandlerExt: TryHandler {} +pub(crate) trait TryHandlerExt: TryHandler {}