aws_multipart_upload/
types.rs

1pub mod api;
2pub mod upload;
3mod write_parts;
4
5use aws_sdk_s3::primitives::ByteStream;
6use futures::future::{ready, BoxFuture};
7use std::sync::Arc;
8
9use self::api::*;
10use crate::AwsError;
11
12/// Operations in a multipart upload.
13pub trait UploadClient {
14    /// Create a new upload returning the ID of the upload.
15    fn new_upload<'a, 'client: 'a>(
16        &'client self,
17        addr: &'a UploadAddress,
18    ) -> BoxFuture<'a, Result<UploadRequestParams, AwsError>>;
19
20    /// Upload one part to the multipart upload.
21    fn upload_part<'a, 'client: 'a>(
22        &'client self,
23        params: &'a UploadRequestParams,
24        part_number: i32,
25        part: ByteStream,
26    ) -> BoxFuture<'a, Result<EntityTag, AwsError>>;
27
28    /// Complete the upload.
29    fn complete_upload<'a, 'client: 'a>(
30        &'client self,
31        params: &'a UploadRequestParams,
32        parts: &'a UploadedParts,
33    ) -> BoxFuture<'a, Result<EntityTag, AwsError>>;
34
35    /// A callback with the `EntityId` returned by `complete_upload`.
36    fn on_upload_complete(&self, _etag: EntityTag) -> BoxFuture<'_, Result<(), AwsError>> {
37        Box::pin(ready(Ok(())))
38    }
39}
40
41impl<U: UploadClient> UploadClient for Arc<U> {
42    fn new_upload<'a, 'client: 'a>(
43        &'client self,
44        addr: &'a UploadAddress,
45    ) -> BoxFuture<'a, Result<UploadRequestParams, AwsError>> {
46        U::new_upload(self, addr)
47    }
48
49    fn upload_part<'a, 'client: 'a>(
50        &'client self,
51        params: &'a UploadRequestParams,
52        part_number: i32,
53        part: ByteStream,
54    ) -> BoxFuture<'a, Result<EntityTag, AwsError>> {
55        U::upload_part(self, params, part_number, part)
56    }
57
58    fn complete_upload<'a, 'client: 'a>(
59        &'client self,
60        params: &'a UploadRequestParams,
61        parts: &'a UploadedParts,
62    ) -> BoxFuture<'a, Result<EntityTag, AwsError>> {
63        U::complete_upload(self, params, parts)
64    }
65
66    fn on_upload_complete(&self, etag: EntityTag) -> BoxFuture<'_, Result<(), AwsError>> {
67        U::on_upload_complete(self, etag)
68    }
69}
70
71/// An interface for controlling the "checkpoints" of uploading parts and
72/// completing uploads.
73pub trait UploadControl {
74    /// The desired part size in bytes.
75    fn target_part_size(&self) -> usize;
76
77    /// Whether one part in the upload is complete.
78    fn is_part_ready(&self, part_size: usize) -> bool {
79        part_size >= self.target_part_size()
80    }
81
82    /// Whether the overall upload is complete.
83    fn is_upload_ready(&self, upload_size: usize, num_parts: usize) -> bool;
84}
85
86impl<C: UploadControl> UploadControl for Arc<C> {
87    fn target_part_size(&self) -> usize {
88        C::target_part_size(self)
89    }
90
91    fn is_upload_ready(&self, upload_size: usize, num_parts: usize) -> bool {
92        C::is_upload_ready(self, upload_size, num_parts)
93    }
94}