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:
Jonathan Reem
2014-09-08 14:04:51 -07:00
parent fd6b014e7e
commit 872dcf758c
3 changed files with 57 additions and 28 deletions

View File

@@ -36,8 +36,13 @@ impl Handler for Echo {
},
(&Post, "/echo") => (), // fall through, fighting mutable borrows
_ => {
<<<<<<< Updated upstream
res.status = hyper::status::NotFound;
try_continue!(res.end());
=======
*res.status_mut() = hyper::status::NotFound;
try_continue!(res.start().and_then(|res| res.end()));
>>>>>>> Stashed changes
continue;
}
},