| @@ -50,19 +50,29 @@ pub trait Header: Any + Send + Sync { | |||||||
| /// A trait for any object that will represent a header field and value. | /// 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. | /// 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. |     /// Format a header to be output into a TcpStream. | ||||||
|     /// |     /// | ||||||
|     /// This method is not allowed to introduce an Err not produced |     /// This method is not allowed to introduce an Err not produced | ||||||
|     /// by the passed-in Formatter. |     /// by the passed-in Formatter. | ||||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result; |     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] |     #[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 { | impl HeaderFormat { | ||||||
|  |     #[inline] | ||||||
|     fn is<T: 'static>(&self) -> bool { |     fn is<T: 'static>(&self) -> bool { | ||||||
|         self.get_type_id() == TypeId::of::<T>() |         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> { | impl Clone for Box<HeaderFormat + Send + Sync> { | ||||||
|  |     #[inline] | ||||||
|     fn clone(&self) -> Box<HeaderFormat + Send + Sync> { |     fn clone(&self) -> Box<HeaderFormat + Send + Sync> { | ||||||
|         self.clone_box() |         self.clone_box() | ||||||
|     } |     } | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								src/net.rs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/net.rs
									
									
									
									
									
								
							| @@ -42,13 +42,21 @@ pub trait NetworkAcceptor<S: NetworkStream>: Acceptor<S> + Clone + Send { | |||||||
| } | } | ||||||
|  |  | ||||||
| /// An abstraction over streams that a Server can utilize. | /// 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. |     /// Get the remote address of the underlying connection. | ||||||
|     fn peer_name(&mut self) -> IoResult<SocketAddr>; |     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] |     #[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. | /// A connector creates a NetworkStream. | ||||||
|   | |||||||
| @@ -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. |     /// 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>> |     pub fn listen_network<H, S, A, L>(self, handler: H, threads: uint) -> HttpResult<Listening<A>> | ||||||
|     where H: Handler, |     where H: Handler, | ||||||
|           S: NetworkStream, |           S: NetworkStream + Clone, | ||||||
|           A: NetworkAcceptor<S>, |           A: NetworkAcceptor<S>, | ||||||
|           L: NetworkListener<S, A>, { |           L: NetworkListener<S, A>, { | ||||||
|         debug!("binding to {}:{}", self.ip, self.port); |         debug!("binding to {}:{}", self.ip, self.port); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user