Skip to main content

rustack_s3_model/
request.rs

1//! Auto-generated from AWS S3 Smithy model. DO NOT EDIT.
2
3/// A wrapper around `bytes::Bytes` for streaming blob data.
4///
5/// In the future, this may be replaced with an actual streaming type.
6#[derive(Debug, Clone, Default)]
7pub struct StreamingBlob {
8    /// The underlying bytes data.
9    pub data: bytes::Bytes,
10}
11
12impl StreamingBlob {
13    /// Create a new `StreamingBlob` from bytes.
14    #[must_use]
15    pub fn new(data: impl Into<bytes::Bytes>) -> Self {
16        Self { data: data.into() }
17    }
18
19    /// Returns true if the blob is empty.
20    #[must_use]
21    pub fn is_empty(&self) -> bool {
22        self.data.is_empty()
23    }
24
25    /// Returns the length of the blob.
26    #[must_use]
27    pub fn len(&self) -> usize {
28        self.data.len()
29    }
30}
31
32impl From<bytes::Bytes> for StreamingBlob {
33    fn from(data: bytes::Bytes) -> Self {
34        Self { data }
35    }
36}
37
38impl From<Vec<u8>> for StreamingBlob {
39    fn from(data: Vec<u8>) -> Self {
40        Self { data: data.into() }
41    }
42}
43
44impl From<&[u8]> for StreamingBlob {
45    fn from(data: &[u8]) -> Self {
46        Self {
47            data: bytes::Bytes::copy_from_slice(data),
48        }
49    }
50}
51
52/// AWS credentials for request authentication.
53#[derive(Clone, Default)]
54pub struct Credentials {
55    /// The AWS access key ID.
56    pub access_key_id: String,
57    /// The AWS secret access key.
58    pub secret_access_key: String,
59    /// Optional session token for temporary credentials.
60    pub session_token: Option<String>,
61}
62
63impl std::fmt::Debug for Credentials {
64    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65        f.debug_struct("Credentials")
66            .field("access_key_id", &self.access_key_id)
67            .field("secret_access_key", &"[REDACTED]")
68            .field(
69                "session_token",
70                &self.session_token.as_ref().map(|_| "[REDACTED]"),
71            )
72            .finish()
73    }
74}
75
76/// An S3 request wrapping an input type with credentials and headers.
77#[derive(Debug, Clone)]
78pub struct S3Request<T> {
79    /// The input payload.
80    pub input: T,
81    /// Optional credentials for the request.
82    pub credentials: Option<Credentials>,
83    /// Additional HTTP headers.
84    pub headers: http::HeaderMap,
85}
86
87impl<T: Default> Default for S3Request<T> {
88    fn default() -> Self {
89        Self {
90            input: T::default(),
91            credentials: None,
92            headers: http::HeaderMap::new(),
93        }
94    }
95}
96
97impl<T> S3Request<T> {
98    /// Create a new S3Request with the given input.
99    #[must_use]
100    pub fn new(input: T) -> Self {
101        Self {
102            input,
103            credentials: None,
104            headers: http::HeaderMap::new(),
105        }
106    }
107
108    /// Set the credentials for this request.
109    #[must_use]
110    pub fn with_credentials(mut self, credentials: Credentials) -> Self {
111        self.credentials = Some(credentials);
112        self
113    }
114
115    /// Map the input type to a different type.
116    pub fn map_input<U>(self, f: impl FnOnce(T) -> U) -> S3Request<U> {
117        S3Request {
118            input: f(self.input),
119            credentials: self.credentials,
120            headers: self.headers,
121        }
122    }
123}