pub struct WriteMultipart { /* private fields */ }Expand description
A synchronous write API for uploading data in parallel in fixed size chunks
Uses multiple tokio tasks in a JoinSet to multiplex upload tasks in parallel
The design also takes inspiration from Sink with WriteMultipart::wait_for_capacity
allowing back pressure on producers, prior to buffering the next part. However, unlike
Sink this back pressure is optional, allowing integration with synchronous producers
Implementations§
Source§impl WriteMultipart
impl WriteMultipart
Sourcepub fn new(upload: Box<dyn MultipartUpload>) -> Self
pub fn new(upload: Box<dyn MultipartUpload>) -> Self
Create a new WriteMultipart that will upload using 5MB chunks
Sourcepub fn new_with_chunk_size(
upload: Box<dyn MultipartUpload>,
chunk_size: usize,
) -> Self
pub fn new_with_chunk_size( upload: Box<dyn MultipartUpload>, chunk_size: usize, ) -> Self
Create a new WriteMultipart that will upload in fixed chunk_size sized chunks
Sourcepub fn poll_for_capacity(
&mut self,
cx: &mut Context<'_>,
max_concurrency: usize,
) -> Poll<Result<()>>
pub fn poll_for_capacity( &mut self, cx: &mut Context<'_>, max_concurrency: usize, ) -> Poll<Result<()>>
Polls for there to be less than max_concurrency UploadPart in progress
See Self::wait_for_capacity for an async version of this function
Sourcepub async fn wait_for_capacity(&mut self, max_concurrency: usize) -> Result<()>
pub async fn wait_for_capacity(&mut self, max_concurrency: usize) -> Result<()>
Wait until there are less than max_concurrency UploadPart in progress
See Self::poll_for_capacity for a Poll version of this function
Sourcepub fn write(&mut self, buf: &[u8])
pub fn write(&mut self, buf: &[u8])
Write data to this WriteMultipart
Data is buffered using PutPayloadMut::extend_from_slice. Implementations looking to
write data from owned buffers may prefer Self::put as this avoids copying.
Note this method is synchronous (not async) and will immediately
start new uploads as soon as the internal chunk_size is hit,
regardless of how many outstanding uploads are already in progress.
Back pressure can optionally be applied to producers by calling
Self::wait_for_capacity prior to calling this method
Sourcepub fn put(&mut self, bytes: Bytes)
pub fn put(&mut self, bytes: Bytes)
Put a chunk of data into this WriteMultipart without copying
Data is buffered using PutPayloadMut::push. Implementations looking to
perform writes from non-owned buffers should prefer Self::write as this
will allow multiple calls to share the same underlying allocation.
See Self::write for information on backpressure
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WriteMultipart
impl !RefUnwindSafe for WriteMultipart
impl Send for WriteMultipart
impl !Sync for WriteMultipart
impl Unpin for WriteMultipart
impl !UnwindSafe for WriteMultipart
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more