Statically track the status of a Response by using a Phantom Type
Introduces two Phantom Types, Fresh and Streaming, which indicate the status of a Response. Response::start translates an Response<Fresh> into a Response<Streaming> by writing the StatusCode and Headers. Response<Fresh> allows modification of Headers and StatusCode, but does not allow writing to the body. Response<Streaming> has the opposite privileges.
This commit is contained in:
@@ -4,7 +4,7 @@ use std::io::{Acceptor, Listener, IoResult, EndOfFile, IncomingConnections};
|
||||
use std::io::net::ip::{IpAddr, Port, SocketAddr};
|
||||
|
||||
pub use self::request::Request;
|
||||
pub use self::response::Response;
|
||||
pub use self::response::{Response, Fresh, Streaming};
|
||||
|
||||
pub mod request;
|
||||
pub mod response;
|
||||
@@ -55,8 +55,8 @@ pub struct Incoming<'a> {
|
||||
from: IncomingConnections<'a, TcpAcceptor>
|
||||
}
|
||||
|
||||
impl<'a> Iterator<(Request, Response)> for Incoming<'a> {
|
||||
fn next(&mut self) -> Option<(Request, Response)> {
|
||||
impl<'a> Iterator<(Request, Response<Fresh>)> for Incoming<'a> {
|
||||
fn next(&mut self) -> Option<(Request, Response<Fresh>)> {
|
||||
for conn in self.from {
|
||||
match conn {
|
||||
Ok(stream) => {
|
||||
|
||||
Reference in New Issue
Block a user