#[derive(Debug, Clone, Default)]
pub struct StreamingBlob {
pub data: bytes::Bytes,
}
impl StreamingBlob {
#[must_use]
pub fn new(data: impl Into<bytes::Bytes>) -> Self {
Self { data: data.into() }
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.data.is_empty()
}
#[must_use]
pub fn len(&self) -> usize {
self.data.len()
}
}
impl From<bytes::Bytes> for StreamingBlob {
fn from(data: bytes::Bytes) -> Self {
Self { data }
}
}
impl From<Vec<u8>> for StreamingBlob {
fn from(data: Vec<u8>) -> Self {
Self { data: data.into() }
}
}
impl From<&[u8]> for StreamingBlob {
fn from(data: &[u8]) -> Self {
Self {
data: bytes::Bytes::copy_from_slice(data),
}
}
}
#[derive(Clone, Default)]
pub struct Credentials {
pub access_key_id: String,
pub secret_access_key: String,
pub session_token: Option<String>,
}
impl std::fmt::Debug for Credentials {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Credentials")
.field("access_key_id", &self.access_key_id)
.field("secret_access_key", &"[REDACTED]")
.field(
"session_token",
&self.session_token.as_ref().map(|_| "[REDACTED]"),
)
.finish()
}
}
#[derive(Debug, Clone)]
pub struct S3Request<T> {
pub input: T,
pub credentials: Option<Credentials>,
pub headers: http::HeaderMap,
}
impl<T: Default> Default for S3Request<T> {
fn default() -> Self {
Self {
input: T::default(),
credentials: None,
headers: http::HeaderMap::new(),
}
}
}
impl<T> S3Request<T> {
#[must_use]
pub fn new(input: T) -> Self {
Self {
input,
credentials: None,
headers: http::HeaderMap::new(),
}
}
#[must_use]
pub fn with_credentials(mut self, credentials: Credentials) -> Self {
self.credentials = Some(credentials);
self
}
pub fn map_input<U>(self, f: impl FnOnce(T) -> U) -> S3Request<U> {
S3Request {
input: f(self.input),
credentials: self.credentials,
headers: self.headers,
}
}
}