Skip to content

Commit 89bedd3

Browse files
committed
rustup for clone trait
1 parent 514f96e commit 89bedd3

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/header/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,29 @@ pub trait Header: Any + Send + Sync {
5050
/// A trait for any object that will represent a header field and value.
5151
///
5252
/// This trait represents the formatting of a Header for output to a TcpStream.
53-
pub trait HeaderFormat: Clone + Any + Send + Sync {
53+
pub trait HeaderFormat: HeaderClone + Any + Send + Sync {
5454
/// Format a header to be output into a TcpStream.
5555
///
5656
/// This method is not allowed to introduce an Err not produced
5757
/// by the passed-in Formatter.
5858
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result;
5959

60-
#[doc(hidden)]
60+
}
61+
62+
#[doc(hidden)]
63+
pub trait HeaderClone {
64+
fn clone_box(&self) -> Box<HeaderFormat + Sync + Send>;
65+
}
66+
67+
impl<T: HeaderFormat + Send + Sync + Clone> HeaderClone for T {
6168
#[inline]
62-
fn clone_box(&self) -> Box<HeaderFormat + Sync + Send> { box self.clone() }
69+
fn clone_box(&self) -> Box<HeaderFormat + Sync + Send> {
70+
box self.clone()
71+
}
6372
}
6473

6574
impl HeaderFormat {
75+
#[inline]
6676
fn is<T: 'static>(&self) -> bool {
6777
self.get_type_id() == TypeId::of::<T>()
6878
}
@@ -85,6 +95,7 @@ impl<'a> UncheckedAnyMutDowncast<'a> for &'a mut HeaderFormat {
8595
}
8696

8797
impl Clone for Box<HeaderFormat + Send + Sync> {
98+
#[inline]
8899
fn clone(&self) -> Box<HeaderFormat + Send + Sync> {
89100
self.clone_box()
90101
}

src/net.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,21 @@ pub trait NetworkAcceptor<S: NetworkStream>: Acceptor<S> + Clone + Send {
4242
}
4343

4444
/// An abstraction over streams that a Server can utilize.
45-
pub trait NetworkStream: Stream + Any + Clone + Send {
45+
pub trait NetworkStream: Stream + Any + StreamClone + Send {
4646
/// Get the remote address of the underlying connection.
4747
fn peer_name(&mut self) -> IoResult<SocketAddr>;
48+
}
49+
50+
#[doc(hidden)]
51+
pub trait StreamClone {
52+
fn clone_box(&self) -> Box<NetworkStream + Send>;
53+
}
4854

49-
#[doc(hidden)]
55+
impl<T: NetworkStream + Send + Clone> StreamClone for T {
5056
#[inline]
51-
fn clone_box(&self) -> Box<NetworkStream + Send> { box self.clone() }
57+
fn clone_box(&self) -> Box<NetworkStream + Send> {
58+
box self.clone()
59+
}
5260
}
5361

5462
/// A connector creates a NetworkStream.

src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<L: NetworkListener<S, A>, S: NetworkStream, A: NetworkAcceptor<S>> Server<L
5757
/// something other than the provided HttpStream, HttpAcceptor, and HttpListener.
5858
pub fn listen_network<H, S, A, L>(self, handler: H, threads: uint) -> HttpResult<Listening<A>>
5959
where H: Handler,
60-
S: NetworkStream,
60+
S: NetworkStream + Clone,
6161
A: NetworkAcceptor<S>,
6262
L: NetworkListener<S, A>, {
6363
debug!("binding to {}:{}", self.ip, self.port);

0 commit comments

Comments
 (0)