rustup for clone trait

This commit is contained in:
Sean McArthur
2014-12-09 16:50:49 -08:00
parent 514f96e9eb
commit 89bedd30ba
3 changed files with 26 additions and 7 deletions

View File

@@ -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<HeaderFormat + Sync + Send>;
}
impl<T: HeaderFormat + Send + Sync + Clone> HeaderClone for T {
#[inline]
fn clone_box(&self) -> Box<HeaderFormat + Sync + Send> { box self.clone() }
fn clone_box(&self) -> Box<HeaderFormat + Sync + Send> {
box self.clone()
}
}
impl HeaderFormat {
#[inline]
fn is<T: 'static>(&self) -> bool {
self.get_type_id() == TypeId::of::<T>()
}
@@ -85,6 +95,7 @@ impl<'a> UncheckedAnyMutDowncast<'a> for &'a mut HeaderFormat {
}
impl Clone for Box<HeaderFormat + Send + Sync> {
#[inline]
fn clone(&self) -> Box<HeaderFormat + Send + Sync> {
self.clone_box()
}

View File

@@ -42,13 +42,21 @@ pub trait NetworkAcceptor<S: NetworkStream>: Acceptor<S> + 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<SocketAddr>;
}
#[doc(hidden)]
#[doc(hidden)]
pub trait StreamClone {
fn clone_box(&self) -> Box<NetworkStream + Send>;
}
impl<T: NetworkStream + Send + Clone> StreamClone for T {
#[inline]
fn clone_box(&self) -> Box<NetworkStream + Send> { box self.clone() }
fn clone_box(&self) -> Box<NetworkStream + Send> {
box self.clone()
}
}
/// A connector creates a NetworkStream.

View File

@@ -57,7 +57,7 @@ impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L
/// something other than the provided HttpStream, HttpAcceptor, and HttpListener.
pub fn listen_network<H, S, A, L>(self, handler: H, threads: uint) -> HttpResult<Listening<A>>
where H: Handler,
S: NetworkStream,
S: NetworkStream + Clone,
A: NetworkAcceptor<S>,
L: NetworkListener<S, A>, {
debug!("binding to {}:{}", self.ip, self.port);