1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-07-01 16:55:08 +02:00

This is a squashed commit:

- Convert MessageBody to accept Pin in poll_next

- add CHANGES and increase versions aligned to semver

- update crates to accomodate MessageBody Pin change

- fix tests and dependencies
This commit is contained in:
Maksym Vorobiov
2020-01-29 11:15:13 +03:00
committed by Yuki Okushi
parent a4148de226
commit 9d04b250f9
24 changed files with 247 additions and 174 deletions

View File

@ -238,19 +238,24 @@ where
}
}
use pin_project::{pin_project, pinned_drop};
#[pin_project(PinnedDrop)]
pub struct StreamLog<B> {
#[pin]
body: ResponseBody<B>,
format: Option<Format>,
size: usize,
time: OffsetDateTime,
}
impl<B> Drop for StreamLog<B> {
fn drop(&mut self) {
if let Some(ref format) = self.format {
#[pinned_drop]
impl<B> PinnedDrop for StreamLog<B> {
fn drop(self: Pin<&mut Self>) {
let this = self.project();
if let Some(ref format) = this.format {
let render = |fmt: &mut Formatter<'_>| {
for unit in &format.0 {
unit.render(fmt, self.size, self.time)?;
unit.render(fmt, *this.size, *this.time)?;
}
Ok(())
};
@ -264,10 +269,11 @@ impl<B: MessageBody> MessageBody for StreamLog<B> {
self.body.size()
}
fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, Error>>> {
match self.body.poll_next(cx) {
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, Error>>> {
let this = self.project();
match this.body.poll_next(cx) {
Poll::Ready(Some(Ok(chunk))) => {
self.size += chunk.len();
*this.size += chunk.len();
Poll::Ready(Some(Ok(chunk)))
}
val => val,