aws_multipart_upload/client/request/
upload_part.rs

1use super::UploadPartRequestBuilder;
2use crate::client::part::{CompletedPart, PartBody, PartNumber};
3use crate::client::{UploadClient, UploadData, UploadId};
4use crate::error::{ErrorRepr, Result};
5use crate::uri::ObjectUri;
6
7use std::fmt::{self, Debug, Formatter};
8use std::pin::Pin;
9use std::task::{Context, Poll};
10
11/// Sending a request to add a part to an existing multpart upload.
12pub struct SendUploadPart(pub(crate) Pin<Box<dyn Future<Output = Result<CompletedPart>>>>);
13
14impl SendUploadPart {
15    /// Create a new `SendUploadPart`.
16    pub fn new(client: &UploadClient, req: UploadPartRequest) -> Self {
17        let cli = client.clone();
18        Self(Box::pin(
19            async move { cli.inner.send_upload_part(req).await },
20        ))
21    }
22}
23
24impl Future for SendUploadPart {
25    type Output = Result<CompletedPart>;
26    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
27        self.0.as_mut().poll(cx)
28    }
29}
30
31impl Debug for SendUploadPart {
32    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
33        f.debug_tuple("SendUploadPart")
34            .field(&"Future<Output = Result<CompletedPart>>")
35            .finish()
36    }
37}
38
39/// Request object for uploading a new part.
40#[derive(Debug, Clone)]
41pub struct UploadPartRequest {
42    pub(crate) id: UploadId,
43    pub(crate) uri: ObjectUri,
44    pub(crate) body: PartBody,
45    pub(crate) part_number: PartNumber,
46}
47
48impl UploadPartRequest {
49    /// Create a new `UploadPartRequest` from the minimum required.
50    pub fn new(data: &UploadData, body: PartBody, part_number: PartNumber) -> Self {
51        Self {
52            id: data.get_id(),
53            uri: data.get_uri(),
54            body,
55            part_number,
56        }
57    }
58
59    /// Set the required properties on the SDK request builder for the operation.
60    pub fn with_builder(&mut self, builder: UploadPartRequestBuilder) -> UploadPartRequestBuilder {
61        builder
62            .upload_id(&*self.id)
63            .bucket(&*self.uri.bucket)
64            .key(&*self.uri.key)
65            .part_number(*self.part_number)
66            .body(self.body.as_sdk_body())
67    }
68
69    /// Returns a reference to the assigned `UploadId` for this request.
70    pub fn id(&self) -> &UploadId {
71        &self.id
72    }
73
74    /// Returns a reference to the `ObjectUri` for this request.
75    pub fn uri(&self) -> &ObjectUri {
76        &self.uri
77    }
78
79    /// Returns a reference to the `PartBody` for this request.
80    pub fn body(&self) -> &PartBody {
81        &self.body
82    }
83
84    /// Returns a reference to the `PartNumber` for this request.
85    pub fn part_number(&self) -> PartNumber {
86        self.part_number
87    }
88
89    pub(crate) fn validate(&self) -> Result<()> {
90        if self.id.is_empty() || self.uri.is_empty() {
91            return Err(
92                ErrorRepr::Missing("UploadPartRequest", "empty upload id and/or uri").into(),
93            );
94        }
95        Ok(())
96    }
97}