mirror of
https://github.com/actix/actix-web.git
synced 2025-01-09 16:55:30 +00:00
Add Unpin to Body to get rid of unsafe in MessageBody
This commit is contained in:
parent
c05f9475c5
commit
a84b37199a
1 changed files with 4 additions and 15 deletions
|
@ -59,21 +59,10 @@ impl<T: MessageBody + Unpin> MessageBody for Box<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, Error>>> {
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, Error>>> {
|
||||||
unsafe { self.map_unchecked_mut(|boxed| boxed.as_mut()) }.poll_next(cx)
|
Pin::new(self.get_mut().as_mut()).poll_next(cx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageBody for Box<dyn MessageBody> {
|
|
||||||
fn size(&self) -> BodySize {
|
|
||||||
self.as_ref().size()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, Error>>> {
|
|
||||||
unsafe { Pin::new_unchecked(self.get_mut().as_mut()) }.poll_next(cx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[pin_project]
|
#[pin_project]
|
||||||
pub enum ResponseBody<B> {
|
pub enum ResponseBody<B> {
|
||||||
Body(#[pin] B),
|
Body(#[pin] B),
|
||||||
|
@ -149,7 +138,7 @@ pub enum Body {
|
||||||
/// Specific response body.
|
/// Specific response body.
|
||||||
Bytes(Bytes),
|
Bytes(Bytes),
|
||||||
/// Generic message body.
|
/// Generic message body.
|
||||||
Message(#[pin] Box<dyn MessageBody>),
|
Message(Box<dyn MessageBody + Unpin>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Body {
|
impl Body {
|
||||||
|
@ -159,7 +148,7 @@ impl Body {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create body from generic message body.
|
/// Create body from generic message body.
|
||||||
pub fn from_message<B: MessageBody + 'static>(body: B) -> Body {
|
pub fn from_message<B: MessageBody + Unpin + 'static>(body: B) -> Body {
|
||||||
Body::Message(Box::new(body))
|
Body::Message(Box::new(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +177,7 @@ impl MessageBody for Body {
|
||||||
Poll::Ready(Some(Ok(mem::replace(bin, Bytes::new()))))
|
Poll::Ready(Some(Ok(mem::replace(bin, Bytes::new()))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Body::Message(body) => body.poll_next(cx),
|
Body::Message(ref mut body) => Pin::new(body.as_mut()).poll_next(cx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue