Skip to main content

aws_multipart_upload/client/request/
create.rs

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