1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 18:34:36 +01: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> {