1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-21 05:05:44 +02:00

improve code readability

This commit is contained in:
Rob Ede
2021-01-04 00:49:02 +00:00
parent e1683313ec
commit 21f6c9d7a5
34 changed files with 238 additions and 230 deletions

View File

@@ -1,9 +1,12 @@
//! HTTP/2 implementation
use std::pin::Pin;
use std::task::{Context, Poll};
//! HTTP/2 implementation.
use std::{
pin::Pin,
task::{Context, Poll},
};
use bytes::Bytes;
use futures_core::Stream;
use futures_core::{ready, Stream};
use h2::RecvStream;
mod dispatcher;
@@ -13,14 +16,14 @@ pub use self::dispatcher::Dispatcher;
pub use self::service::H2Service;
use crate::error::PayloadError;
/// H2 receive stream
/// HTTP/2 peer stream.
pub struct Payload {
pl: RecvStream,
stream: RecvStream,
}
impl Payload {
pub(crate) fn new(pl: RecvStream) -> Self {
Self { pl }
pub(crate) fn new(stream: RecvStream) -> Self {
Self { stream }
}
}
@@ -33,18 +36,17 @@ impl Stream for Payload {
) -> Poll<Option<Self::Item>> {
let this = self.get_mut();
match Pin::new(&mut this.pl).poll_data(cx) {
Poll::Ready(Some(Ok(chunk))) => {
match ready!(Pin::new(&mut this.stream).poll_data(cx)) {
Some(Ok(chunk)) => {
let len = chunk.len();
if let Err(err) = this.pl.flow_control().release_capacity(len) {
Poll::Ready(Some(Err(err.into())))
} else {
Poll::Ready(Some(Ok(chunk)))
match this.stream.flow_control().release_capacity(len) {
Ok(()) => Poll::Ready(Some(Ok(chunk))),
Err(err) => Poll::Ready(Some(Err(err.into()))),
}
}
Poll::Ready(Some(Err(err))) => Poll::Ready(Some(Err(err.into()))),
Poll::Pending => Poll::Pending,
Poll::Ready(None) => Poll::Ready(None),
Some(Err(err)) => Poll::Ready(Some(Err(err.into()))),
None => Poll::Ready(None),
}
}
}