diff --git a/src/header/mod.rs b/src/header/mod.rs index 3d052018..440d55b2 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -50,19 +50,29 @@ pub trait Header: Any + Send + Sync { /// A trait for any object that will represent a header field and value. /// /// This trait represents the formatting of a Header for output to a TcpStream. -pub trait HeaderFormat: Clone + Any + Send + Sync { +pub trait HeaderFormat: HeaderClone + Any + Send + Sync { /// Format a header to be output into a TcpStream. /// /// This method is not allowed to introduce an Err not produced /// by the passed-in Formatter. fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result; - #[doc(hidden)] +} + +#[doc(hidden)] +pub trait HeaderClone { + fn clone_box(&self) -> Box; +} + +impl HeaderClone for T { #[inline] - fn clone_box(&self) -> Box { box self.clone() } + fn clone_box(&self) -> Box { + box self.clone() + } } impl HeaderFormat { + #[inline] fn is(&self) -> bool { self.get_type_id() == TypeId::of::() } @@ -85,6 +95,7 @@ impl<'a> UncheckedAnyMutDowncast<'a> for &'a mut HeaderFormat { } impl Clone for Box { + #[inline] fn clone(&self) -> Box { self.clone_box() } diff --git a/src/net.rs b/src/net.rs index 0f2207f4..11ad5ba1 100644 --- a/src/net.rs +++ b/src/net.rs @@ -42,13 +42,21 @@ pub trait NetworkAcceptor: Acceptor + Clone + Send { } /// An abstraction over streams that a Server can utilize. -pub trait NetworkStream: Stream + Any + Clone + Send { +pub trait NetworkStream: Stream + Any + StreamClone + Send { /// Get the remote address of the underlying connection. fn peer_name(&mut self) -> IoResult; +} - #[doc(hidden)] +#[doc(hidden)] +pub trait StreamClone { + fn clone_box(&self) -> Box; +} + +impl StreamClone for T { #[inline] - fn clone_box(&self) -> Box { box self.clone() } + fn clone_box(&self) -> Box { + box self.clone() + } } /// A connector creates a NetworkStream. diff --git a/src/server/mod.rs b/src/server/mod.rs index 7058e0fb..10ae4660 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -57,7 +57,7 @@ impl, S: NetworkStream, A: NetworkAcceptor> Server(self, handler: H, threads: uint) -> HttpResult> where H: Handler, - S: NetworkStream, + S: NetworkStream + Clone, A: NetworkAcceptor, L: NetworkListener, { debug!("binding to {}:{}", self.ip, self.port);