todo:Error

This commit is contained in:
weisd
2024-07-02 17:01:54 +08:00
parent ace3fbdfa0
commit 5eb6d52daf
6 changed files with 50 additions and 45 deletions
+8 -8
View File
@@ -1,7 +1,7 @@
use anyhow::Error;
use bytes::Bytes;
use futures::pin_mut;
use futures::stream::{Stream, StreamExt};
use s3s::StdError;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
@@ -11,7 +11,7 @@ pub type SyncBoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + Sync + '
pub struct ChunkedStream {
/// inner
inner: AsyncTryStream<Bytes, Error, SyncBoxFuture<'static, Result<(), Error>>>,
inner: AsyncTryStream<Bytes, StdError, SyncBoxFuture<'static, Result<(), StdError>>>,
remaining_length: usize,
}
@@ -19,9 +19,9 @@ pub struct ChunkedStream {
impl ChunkedStream {
pub fn new<S>(body: S, content_length: usize, chunk_size: usize, need_padding: bool) -> Self
where
S: Stream<Item = Result<Bytes, Error>> + Send + Sync + 'static,
S: Stream<Item = Result<Bytes, StdError>> + Send + Sync + 'static,
{
let inner = AsyncTryStream::<_, _, SyncBoxFuture<'static, Result<(), Error>>>::new(|mut y| {
let inner = AsyncTryStream::<_, _, SyncBoxFuture<'static, Result<(), StdError>>>::new(|mut y| {
#[allow(clippy::shadow_same)] // necessary for `pin_mut!`
Box::pin(async move {
pin_mut!(body);
@@ -88,9 +88,9 @@ impl ChunkedStream {
mut body: Pin<&mut S>,
prev_bytes: Bytes,
data_size: usize,
) -> Option<Result<(Vec<Bytes>, Bytes), Error>>
) -> Option<Result<(Vec<Bytes>, Bytes), StdError>>
where
S: Stream<Item = Result<Bytes, Error>> + Send + 'static,
S: Stream<Item = Result<Bytes, StdError>> + Send + 'static,
{
let mut bytes_buffer = Vec::new();
@@ -184,7 +184,7 @@ impl ChunkedStream {
Some(Ok((bytes_buffer, remaining_bytes)))
}
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, Error>>> {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bytes, StdError>>> {
let ans = Pin::new(&mut self.inner).poll_next(cx);
if let Poll::Ready(Some(Ok(ref bytes))) = ans {
self.remaining_length = self.remaining_length.saturating_sub(bytes.len());
@@ -198,7 +198,7 @@ impl ChunkedStream {
}
impl Stream for ChunkedStream {
type Item = Result<Bytes, Error>;
type Item = Result<Bytes, StdError>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.poll(cx)