aws_multipart_upload/client/request/
upload_part.rs1use std::fmt::{self, Debug, Formatter};
2use std::pin::Pin;
3use std::task::{Context, Poll};
4
5use futures::future::BoxFuture;
6
7use super::UploadPartRequestBuilder;
8use crate::client::part::{CompletedPart, PartBody, PartNumber};
9use crate::client::{UploadClient, UploadData, UploadId};
10use crate::error::{ErrorRepr, Result};
11use crate::uri::ObjectUri;
12
13pub struct SendUploadPart(pub(crate) BoxFuture<'static, Result<CompletedPart>>);
15
16impl SendUploadPart {
17 pub fn new(client: &UploadClient, req: UploadPartRequest) -> Self {
19 let cli = client.clone();
20 Self(Box::pin(async move { cli.inner.send_upload_part(req).await }))
21 }
22}
23
24impl Future for SendUploadPart {
25 type Output = Result<CompletedPart>;
26
27 fn poll(
28 mut self: Pin<&mut Self>,
29 cx: &mut Context<'_>,
30 ) -> Poll<Self::Output> {
31 self.0.as_mut().poll(cx)
32 }
33}
34
35impl Debug for SendUploadPart {
36 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
37 f.debug_tuple("SendUploadPart").finish()
38 }
39}
40
41#[derive(Debug, Clone)]
43pub struct UploadPartRequest {
44 pub(crate) id: UploadId,
45 pub(crate) uri: ObjectUri,
46 pub(crate) body: PartBody,
47 pub(crate) part_number: PartNumber,
48}
49
50impl UploadPartRequest {
51 pub fn new(
53 data: &UploadData,
54 body: PartBody,
55 part_number: PartNumber,
56 ) -> Self {
57 Self { id: data.get_id(), uri: data.get_uri(), body, part_number }
58 }
59
60 pub fn with_builder(
63 &mut self,
64 builder: UploadPartRequestBuilder,
65 ) -> UploadPartRequestBuilder {
66 builder
67 .upload_id(&*self.id)
68 .bucket(&*self.uri.bucket)
69 .key(&*self.uri.key)
70 .part_number(*self.part_number)
71 .body(self.body.as_sdk_body())
72 }
73
74 pub fn id(&self) -> &UploadId {
76 &self.id
77 }
78
79 pub fn uri(&self) -> &ObjectUri {
81 &self.uri
82 }
83
84 pub fn body(&self) -> &PartBody {
86 &self.body
87 }
88
89 pub fn part_number(&self) -> PartNumber {
91 self.part_number
92 }
93
94 pub(crate) fn validate(&self) -> Result<()> {
95 if self.id.is_empty() || self.uri.is_empty() {
96 return Err(ErrorRepr::Missing(
97 "UploadPartRequest",
98 "empty upload id and/or uri",
99 )
100 .into());
101 }
102 Ok(())
103 }
104}