rustack_s3_model/
request.rs1#[derive(Debug, Clone, Default)]
7pub struct StreamingBlob {
8 pub data: bytes::Bytes,
10}
11
12impl StreamingBlob {
13 #[must_use]
15 pub fn new(data: impl Into<bytes::Bytes>) -> Self {
16 Self { data: data.into() }
17 }
18
19 #[must_use]
21 pub fn is_empty(&self) -> bool {
22 self.data.is_empty()
23 }
24
25 #[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#[derive(Clone, Default)]
54pub struct Credentials {
55 pub access_key_id: String,
57 pub secret_access_key: String,
59 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#[derive(Debug, Clone)]
78pub struct S3Request<T> {
79 pub input: T,
81 pub credentials: Option<Credentials>,
83 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 #[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 #[must_use]
110 pub fn with_credentials(mut self, credentials: Credentials) -> Self {
111 self.credentials = Some(credentials);
112 self
113 }
114
115 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}