aws_multipart_upload/client/request/
create.rs

1use super::CreateRequestBuilder;
2use crate::client::{UploadClient, UploadData};
3use crate::error::{ErrorRepr, Result};
4use crate::uri::ObjectUri;
5
6use std::fmt::{self, Debug, Formatter};
7use std::pin::Pin;
8use std::task::{Context, Poll};
9
10/// Sending a request to create a new upload.
11pub struct SendCreateUpload(pub(crate) Pin<Box<dyn Future<Output = Result<UploadData>>>>);
12
13impl SendCreateUpload {
14    /// Create a new `SendCreateUpload`.
15    pub fn new(client: &UploadClient, req: CreateRequest) -> Self {
16        let cli = client.clone();
17        Self(Box::pin(
18            async move { cli.inner.send_create_upload(req).await },
19        ))
20    }
21}
22
23impl Future for SendCreateUpload {
24    type Output = Result<UploadData>;
25    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
26        self.0.as_mut().poll(cx)
27    }
28}
29
30impl Debug for SendCreateUpload {
31    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
32        f.debug_tuple("SendCreateUpload")
33            .field(&"Future<Output = Result<UploadData>>")
34            .finish()
35    }
36}
37
38/// Request object for creating a new multipart upload.
39#[derive(Debug, Clone)]
40pub struct CreateRequest {
41    pub(crate) uri: ObjectUri,
42}
43
44impl CreateRequest {
45    /// Create a new `CreateRequest` from the minimum required.
46    pub fn new(uri: ObjectUri) -> Self {
47        Self { uri }
48    }
49
50    /// Set the required properties on the SDK request builder for the operation.
51    pub fn with_builder(&self, builder: CreateRequestBuilder) -> CreateRequestBuilder {
52        builder.bucket(&*self.uri.bucket).key(&*self.uri.key)
53    }
54
55    /// Returns a reference to the `ObjectUri` for this request.
56    pub fn uri(&self) -> &ObjectUri {
57        &self.uri
58    }
59
60    pub(crate) fn validate(&self) -> Result<()> {
61        if self.uri.is_empty() {
62            return Err(ErrorRepr::Missing("CreateRequest", "empty object uri").into());
63        }
64        Ok(())
65    }
66}