Moved WriteStatus, Fresh, and Streaming in to the net module.
This commit is contained in:
		
				
					committed by
					
						 Sean McArthur
						Sean McArthur
					
				
			
			
				
	
			
			
			
						parent
						
							d5c6f33c34
						
					
				
				
					commit
					4115c0e219
				
			| @@ -8,9 +8,9 @@ use std::io::net::ip::Ipv4Addr; | |||||||
| use std::sync::Arc; | use std::sync::Arc; | ||||||
|  |  | ||||||
| use hyper::{Get, Post}; | use hyper::{Get, Post}; | ||||||
| use hyper::server::{Server, Handler, Incoming, Request, Response, Fresh}; | use hyper::server::{Server, Handler, Incoming, Request, Response}; | ||||||
| use hyper::header::common::ContentLength; | use hyper::header::common::ContentLength; | ||||||
| use hyper::net::{HttpStream, HttpAcceptor}; | use hyper::net::{HttpStream, HttpAcceptor, Fresh}; | ||||||
|  |  | ||||||
| trait ConcurrentHandler: Send + Sync { | trait ConcurrentHandler: Send + Sync { | ||||||
|     fn handle(&self, req: Request, res: Response<Fresh>); |     fn handle(&self, req: Request, res: Response<Fresh>); | ||||||
|   | |||||||
| @@ -6,28 +6,11 @@ use url::Url; | |||||||
| use method::{mod, Get, Post, Delete, Put, Patch, Head, Options}; | use method::{mod, Get, Post, Delete, Put, Patch, Head, Options}; | ||||||
| use header::Headers; | use header::Headers; | ||||||
| use header::common::Host; | use header::common::Host; | ||||||
| use net::{NetworkStream, HttpStream}; | use net::{NetworkStream, HttpStream, WriteStatus, Fresh, Streaming}; | ||||||
| use http::LINE_ENDING; | use http::LINE_ENDING; | ||||||
| use version; | use version; | ||||||
| use {HttpResult, HttpUriError}; | use {HttpResult, HttpUriError}; | ||||||
| use super::Response; | use client::Response; | ||||||
|  |  | ||||||
| /// The write-status of a Request that has not had its headers written. |  | ||||||
| pub struct Fresh; |  | ||||||
|  |  | ||||||
| /// The write-status of a Request that has had its headers written. |  | ||||||
| pub struct Streaming; |  | ||||||
|  |  | ||||||
| /// The write-status of a Request |  | ||||||
| pub trait WriteStatus: Private {} |  | ||||||
| impl WriteStatus for Fresh {} |  | ||||||
| impl WriteStatus for Streaming {} |  | ||||||
|  |  | ||||||
| // Only Fresh and Streaming can be WriteStatus |  | ||||||
| #[doc(hidden)] |  | ||||||
| trait Private {} |  | ||||||
| impl Private for Fresh {} |  | ||||||
| impl Private for Streaming {} |  | ||||||
|  |  | ||||||
| /// A client request to a remote server. | /// A client request to a remote server. | ||||||
| pub struct Request<W: WriteStatus> { | pub struct Request<W: WriteStatus> { | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								src/net.rs
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/net.rs
									
									
									
									
									
								
							| @@ -3,6 +3,23 @@ use std::io::{IoResult, Stream, Listener, Acceptor}; | |||||||
| use std::io::net::ip::{SocketAddr, Port}; | use std::io::net::ip::{SocketAddr, Port}; | ||||||
| use std::io::net::tcp::{TcpStream, TcpListener, TcpAcceptor}; | use std::io::net::tcp::{TcpStream, TcpListener, TcpAcceptor}; | ||||||
|  |  | ||||||
|  | /// The write-status indicating headers have not been written. | ||||||
|  | pub struct Fresh; | ||||||
|  |  | ||||||
|  | /// The write-status indicating headers have been written. | ||||||
|  | pub struct Streaming; | ||||||
|  |  | ||||||
|  | /// The write-status of a Request | ||||||
|  | pub trait WriteStatus: Private {} | ||||||
|  | impl WriteStatus for Fresh {} | ||||||
|  | impl WriteStatus for Streaming {} | ||||||
|  |  | ||||||
|  | // Only Fresh and Streaming can be WriteStatus | ||||||
|  | #[doc(hidden)] | ||||||
|  | trait Private {} | ||||||
|  | impl Private for Fresh {} | ||||||
|  | impl Private for Streaming {} | ||||||
|  |  | ||||||
| /// An abstraction to listen for connections on a certain port. | /// An abstraction to listen for connections on a certain port. | ||||||
| pub trait NetworkListener<S: NetworkStream, A: NetworkAcceptor<S>>: Listener<S, A> { | pub trait NetworkListener<S: NetworkStream, A: NetworkAcceptor<S>>: Listener<S, A> { | ||||||
|     /// Bind to a socket. |     /// Bind to a socket. | ||||||
|   | |||||||
| @@ -6,11 +6,12 @@ use intertwine::{Intertwine, Intertwined}; | |||||||
| use macceptor::MoveAcceptor; | use macceptor::MoveAcceptor; | ||||||
|  |  | ||||||
| pub use self::request::Request; | pub use self::request::Request; | ||||||
| pub use self::response::{Response, Fresh, Streaming}; | pub use self::response::Response; | ||||||
|  |  | ||||||
| use net::{NetworkListener, NetworkAcceptor, NetworkStream, HttpAcceptor, HttpListener, HttpStream}; |  | ||||||
|  |  | ||||||
| use {HttpResult}; | use {HttpResult}; | ||||||
|  | use net::{NetworkListener, NetworkAcceptor, NetworkStream, | ||||||
|  |           HttpAcceptor, HttpListener, HttpStream, | ||||||
|  |           Fresh}; | ||||||
|  |  | ||||||
| pub mod request; | pub mod request; | ||||||
| pub mod response; | pub mod response; | ||||||
|   | |||||||
| @@ -10,21 +10,9 @@ use header; | |||||||
| use header::common; | use header::common; | ||||||
| use http::{CR, LF, LINE_ENDING}; | use http::{CR, LF, LINE_ENDING}; | ||||||
| use status; | use status; | ||||||
| use net::NetworkStream; | use net::{NetworkStream, WriteStatus, Fresh, Streaming}; | ||||||
| use version; | use version; | ||||||
|  |  | ||||||
| /// Phantom type indicating Headers and StatusCode have not been written. |  | ||||||
| pub struct Fresh; |  | ||||||
|  |  | ||||||
| /// Phantom type indicating Headers and StatusCode have been written. |  | ||||||
| pub struct Streaming; |  | ||||||
|  |  | ||||||
| /// The status of a Response, indicating if the headers and status have been written. |  | ||||||
| pub trait WriteStatus {} |  | ||||||
|  |  | ||||||
| impl WriteStatus for Streaming {} |  | ||||||
| impl WriteStatus for Fresh {} |  | ||||||
|  |  | ||||||
| /// The outgoing half for a Tcp connection, created by a `Server` and given to a `Handler`. | /// The outgoing half for a Tcp connection, created by a `Server` and given to a `Handler`. | ||||||
| pub struct Response<W: WriteStatus> { | pub struct Response<W: WriteStatus> { | ||||||
|     /// The HTTP version of this response. |     /// The HTTP version of this response. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user