Skip to content

Commit

Permalink
async-multipart: impl Stream for Multipart<Bytes>
Browse files Browse the repository at this point in the history
  • Loading branch information
shikhar committed Jul 19, 2021
1 parent cbbcf29 commit 324ca1a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/v1/objects/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
use futures_util::{
io::{AsyncRead, Result as FuturesResult},
task::{Context, Poll},
Stream,
};
#[cfg(feature = "async-multipart")]
use pin_utils::unsafe_pinned;
Expand Down Expand Up @@ -293,6 +294,29 @@ impl<B: AsyncRead + Unpin> AsyncRead for Multipart<B> {
}
}

#[cfg(feature = "async-multipart")]
impl Stream for Multipart<bytes::Bytes> {
type Item = bytes::Bytes;

fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Poll::Ready(match self.cursor.part {
MultipartPart::Prefix => {
self.cursor.part.next();
Some(self.prefix.clone())
}
MultipartPart::Body => {
self.cursor.part.next();
Some(self.body.clone())
}
MultipartPart::Suffix => {
self.cursor.part.next();
Some(bytes::Bytes::from(MULTI_PART_SUFFIX))
}
MultipartPart::End => None,
})
}
}

impl super::Object {
/// Stores a new object and metadata.
///
Expand Down

0 comments on commit 324ca1a

Please sign in to comment.