aws_multipart_upload/client/request/
complete.rs1use std::fmt::{self, Debug, Formatter};
2use std::pin::Pin;
3use std::task::{Context, Poll};
4
5use aws_sdk::types::CompletedMultipartUpload;
6use futures::future::BoxFuture;
7
8use super::CompleteRequestBuilder;
9use crate::client::part::{CompletedParts, EntityTag};
10use crate::client::{UploadClient, UploadData, UploadId};
11use crate::error::{ErrorRepr, Result};
12use crate::uri::ObjectUri;
13
14pub struct SendCompleteUpload(
16 pub(crate) BoxFuture<'static, Result<CompletedUpload>>,
17);
18
19impl SendCompleteUpload {
20 pub fn new(client: &UploadClient, req: CompleteRequest) -> Self {
22 let cli = client.clone();
23 Self(Box::pin(async move { cli.inner.send_complete_upload(req).await }))
24 }
25}
26
27impl Future for SendCompleteUpload {
28 type Output = Result<CompletedUpload>;
29
30 fn poll(
31 mut self: Pin<&mut Self>,
32 cx: &mut Context<'_>,
33 ) -> Poll<Self::Output> {
34 self.0.as_mut().poll(cx)
35 }
36}
37
38impl Debug for SendCompleteUpload {
39 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
40 f.debug_tuple("SendCompleteUpload").finish()
41 }
42}
43
44#[derive(Debug, Clone)]
46pub struct CompleteRequest {
47 pub(crate) id: UploadId,
48 pub(crate) uri: ObjectUri,
49 pub(crate) completed: CompletedParts,
50}
51
52impl CompleteRequest {
53 pub fn new(data: &UploadData, completed: CompletedParts) -> Self {
55 Self { id: data.get_id(), uri: data.get_uri(), completed }
56 }
57
58 pub fn with_builder(
61 &self,
62 builder: CompleteRequestBuilder,
63 ) -> CompleteRequestBuilder {
64 let parts = CompletedMultipartUpload::from(&self.completed);
65 builder
66 .upload_id(&*self.id)
67 .bucket(&*self.uri.bucket)
68 .key(&*self.uri.key)
69 .multipart_upload(parts)
70 }
71
72 pub fn id(&self) -> &UploadId {
74 &self.id
75 }
76
77 pub fn uri(&self) -> &ObjectUri {
79 &self.uri
80 }
81
82 pub fn completed_parts(&self) -> &CompletedParts {
84 &self.completed
85 }
86
87 pub(crate) fn validate(&self) -> Result<()> {
88 if self.id.is_empty()
89 || self.uri.is_empty()
90 || self.completed_parts().count() == 0
91 {
92 return Err(ErrorRepr::Missing(
93 "CompleteUploadRequest",
94 "invalid upload data",
95 )
96 .into());
97 }
98 Ok(())
99 }
100}
101
102#[derive(Debug, Clone, Default)]
104pub struct CompletedUpload {
105 pub uri: ObjectUri,
107 pub etag: EntityTag,
109}
110
111impl CompletedUpload {
112 pub fn new(uri: ObjectUri, etag: EntityTag) -> Self {
114 Self { uri, etag }
115 }
116}