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