1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-21 07:36:43 +00:00

allow to extract body from response

This commit is contained in:
Nikolay Kim 2019-03-05 21:15:18 -08:00
parent d85468f7e1
commit 34c8b95a35
2 changed files with 11 additions and 0 deletions

View file

@ -59,6 +59,12 @@ impl ResponseBody<Body> {
}
}
impl<B> ResponseBody<B> {
pub fn take_body(&mut self) -> ResponseBody<B> {
std::mem::replace(self, ResponseBody::Other(Body::None))
}
}
impl<B: MessageBody> ResponseBody<B> {
pub fn as_ref(&self) -> Option<&B> {
if let ResponseBody::Body(ref b) = self {

View file

@ -254,6 +254,11 @@ impl<B> Response<B> {
error: self.error,
}
}
/// Extract response body
pub fn take_body(&mut self) -> ResponseBody<B> {
self.body.take_body()
}
}
impl<B: MessageBody> fmt::Debug for Response<B> {