use crate::options;
use crate::raw::*;
use std::collections::HashMap;
#[derive(Debug, Clone, Default)]
pub struct OpCreateDir {}
impl OpCreateDir {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Debug, Clone, Default, Eq, Hash, PartialEq)]
pub struct OpDelete {
version: Option<String>,
recursive: bool,
}
impl OpDelete {
pub fn new() -> Self {
Self::default()
}
}
impl OpDelete {
pub fn with_version(mut self, version: &str) -> Self {
self.version = Some(version.into());
self
}
pub fn with_recursive(mut self, recursive: bool) -> Self {
self.recursive = recursive;
self
}
pub fn version(&self) -> Option<&str> {
self.version.as_deref()
}
pub fn recursive(&self) -> bool {
self.recursive
}
}
impl From<options::DeleteOptions> for OpDelete {
fn from(value: options::DeleteOptions) -> Self {
Self {
version: value.version,
recursive: value.recursive,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct OpDeleter {}
impl OpDeleter {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Debug, Clone, Default)]
pub struct OpList {
limit: Option<usize>,
start_after: Option<String>,
recursive: bool,
versions: bool,
deleted: bool,
}
impl OpList {
pub fn new() -> Self {
Self::default()
}
pub fn with_limit(mut self, limit: usize) -> Self {
self.limit = Some(limit);
self
}
pub fn limit(&self) -> Option<usize> {
self.limit
}
pub fn with_start_after(mut self, start_after: &str) -> Self {
self.start_after = Some(start_after.into());
self
}
pub fn start_after(&self) -> Option<&str> {
self.start_after.as_deref()
}
pub fn with_recursive(mut self, recursive: bool) -> Self {
self.recursive = recursive;
self
}
pub fn recursive(&self) -> bool {
self.recursive
}
#[deprecated(since = "0.53.2", note = "concurrent in list is no-op")]
pub fn with_concurrent(self, concurrent: usize) -> Self {
let _ = concurrent;
self
}
#[deprecated(since = "0.53.2", note = "concurrent in list is no-op")]
pub fn concurrent(&self) -> usize {
0
}
pub fn with_versions(mut self, versions: bool) -> Self {
self.versions = versions;
self
}
pub fn versions(&self) -> bool {
self.versions
}
pub fn with_deleted(mut self, deleted: bool) -> Self {
self.deleted = deleted;
self
}
pub fn deleted(&self) -> bool {
self.deleted
}
}
impl From<options::ListOptions> for OpList {
fn from(value: options::ListOptions) -> Self {
Self {
limit: value.limit,
start_after: value.start_after,
recursive: value.recursive,
versions: value.versions,
deleted: value.deleted,
}
}
}
#[derive(Debug, Clone)]
pub struct OpPresign {
expire: Duration,
op: PresignOperation,
}
impl OpPresign {
pub fn new(op: impl Into<PresignOperation>, expire: Duration) -> Self {
Self {
op: op.into(),
expire,
}
}
pub fn operation(&self) -> &PresignOperation {
&self.op
}
pub fn expire(&self) -> Duration {
self.expire
}
pub fn into_parts(self) -> (Duration, PresignOperation) {
(self.expire, self.op)
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum PresignOperation {
Stat(OpStat),
Read(OpRead),
Write(OpWrite),
Delete(OpDelete),
}
impl From<OpStat> for PresignOperation {
fn from(op: OpStat) -> Self {
Self::Stat(op)
}
}
impl From<OpRead> for PresignOperation {
fn from(v: OpRead) -> Self {
Self::Read(v)
}
}
impl From<OpWrite> for PresignOperation {
fn from(v: OpWrite) -> Self {
Self::Write(v)
}
}
impl From<OpDelete> for PresignOperation {
fn from(v: OpDelete) -> Self {
Self::Delete(v)
}
}
#[derive(Debug, Clone, Default)]
pub struct OpRead {
range: BytesRange,
if_match: Option<String>,
if_none_match: Option<String>,
if_modified_since: Option<Timestamp>,
if_unmodified_since: Option<Timestamp>,
override_content_type: Option<String>,
override_cache_control: Option<String>,
override_content_disposition: Option<String>,
version: Option<String>,
}
impl OpRead {
pub fn new() -> Self {
Self::default()
}
pub fn with_range(mut self, range: BytesRange) -> Self {
self.range = range;
self
}
pub fn range(&self) -> BytesRange {
self.range
}
pub fn range_mut(&mut self) -> &mut BytesRange {
&mut self.range
}
pub fn with_override_content_disposition(mut self, content_disposition: &str) -> Self {
self.override_content_disposition = Some(content_disposition.into());
self
}
pub fn override_content_disposition(&self) -> Option<&str> {
self.override_content_disposition.as_deref()
}
pub fn with_override_cache_control(mut self, cache_control: &str) -> Self {
self.override_cache_control = Some(cache_control.into());
self
}
pub fn override_cache_control(&self) -> Option<&str> {
self.override_cache_control.as_deref()
}
pub fn with_override_content_type(mut self, content_type: &str) -> Self {
self.override_content_type = Some(content_type.into());
self
}
pub fn override_content_type(&self) -> Option<&str> {
self.override_content_type.as_deref()
}
pub fn with_if_match(mut self, if_match: &str) -> Self {
self.if_match = Some(if_match.to_string());
self
}
pub fn if_match(&self) -> Option<&str> {
self.if_match.as_deref()
}
pub fn with_if_none_match(mut self, if_none_match: &str) -> Self {
self.if_none_match = Some(if_none_match.to_string());
self
}
pub fn if_none_match(&self) -> Option<&str> {
self.if_none_match.as_deref()
}
pub fn with_if_modified_since(mut self, v: Timestamp) -> Self {
self.if_modified_since = Some(v);
self
}
pub fn if_modified_since(&self) -> Option<Timestamp> {
self.if_modified_since
}
pub fn with_if_unmodified_since(mut self, v: Timestamp) -> Self {
self.if_unmodified_since = Some(v);
self
}
pub fn if_unmodified_since(&self) -> Option<Timestamp> {
self.if_unmodified_since
}
pub fn with_version(mut self, version: &str) -> Self {
self.version = Some(version.to_string());
self
}
pub fn version(&self) -> Option<&str> {
self.version.as_deref()
}
}
#[derive(Debug, Clone)]
pub struct OpReader {
concurrent: usize,
chunk: Option<usize>,
gap: Option<usize>,
prefetch: usize,
}
impl Default for OpReader {
fn default() -> Self {
Self {
concurrent: 1,
chunk: None,
gap: None,
prefetch: 0,
}
}
}
impl OpReader {
pub fn new() -> Self {
Self::default()
}
pub fn with_concurrent(mut self, concurrent: usize) -> Self {
self.concurrent = concurrent.max(1);
self
}
pub fn concurrent(&self) -> usize {
self.concurrent
}
pub fn with_chunk(mut self, chunk: usize) -> Self {
self.chunk = Some(chunk.max(1));
self
}
pub fn chunk(&self) -> Option<usize> {
self.chunk
}
pub fn with_gap(mut self, gap: usize) -> Self {
self.gap = Some(gap.max(1));
self
}
pub fn gap(&self) -> Option<usize> {
self.gap
}
pub fn with_prefetch(mut self, prefetch: usize) -> Self {
self.prefetch = prefetch;
self
}
pub fn prefetch(&self) -> usize {
self.prefetch
}
}
impl From<options::ReadOptions> for (OpRead, OpReader) {
fn from(value: options::ReadOptions) -> Self {
(
OpRead {
range: value.range,
if_match: value.if_match,
if_none_match: value.if_none_match,
if_modified_since: value.if_modified_since,
if_unmodified_since: value.if_unmodified_since,
override_content_type: value.override_content_type,
override_cache_control: value.override_cache_control,
override_content_disposition: value.override_content_disposition,
version: value.version,
},
OpReader {
concurrent: value.concurrent.max(1),
chunk: value.chunk,
gap: value.gap,
prefetch: 0,
},
)
}
}
impl From<options::ReaderOptions> for (OpRead, OpReader) {
fn from(value: options::ReaderOptions) -> Self {
(
OpRead {
range: BytesRange::default(),
if_match: value.if_match,
if_none_match: value.if_none_match,
if_modified_since: value.if_modified_since,
if_unmodified_since: value.if_unmodified_since,
override_content_type: None,
override_cache_control: None,
override_content_disposition: None,
version: value.version,
},
OpReader {
concurrent: value.concurrent.max(1),
chunk: value.chunk,
gap: value.gap,
prefetch: value.prefetch,
},
)
}
}
#[derive(Debug, Clone, Default)]
pub struct OpStat {
if_match: Option<String>,
if_none_match: Option<String>,
if_modified_since: Option<Timestamp>,
if_unmodified_since: Option<Timestamp>,
override_content_type: Option<String>,
override_cache_control: Option<String>,
override_content_disposition: Option<String>,
version: Option<String>,
}
impl OpStat {
pub fn new() -> Self {
Self::default()
}
pub fn with_if_match(mut self, if_match: &str) -> Self {
self.if_match = Some(if_match.to_string());
self
}
pub fn if_match(&self) -> Option<&str> {
self.if_match.as_deref()
}
pub fn with_if_none_match(mut self, if_none_match: &str) -> Self {
self.if_none_match = Some(if_none_match.to_string());
self
}
pub fn if_none_match(&self) -> Option<&str> {
self.if_none_match.as_deref()
}
pub fn with_if_modified_since(mut self, v: Timestamp) -> Self {
self.if_modified_since = Some(v);
self
}
pub fn if_modified_since(&self) -> Option<Timestamp> {
self.if_modified_since
}
pub fn with_if_unmodified_since(mut self, v: Timestamp) -> Self {
self.if_unmodified_since = Some(v);
self
}
pub fn if_unmodified_since(&self) -> Option<Timestamp> {
self.if_unmodified_since
}
pub fn with_override_content_disposition(mut self, content_disposition: &str) -> Self {
self.override_content_disposition = Some(content_disposition.into());
self
}
pub fn override_content_disposition(&self) -> Option<&str> {
self.override_content_disposition.as_deref()
}
pub fn with_override_cache_control(mut self, cache_control: &str) -> Self {
self.override_cache_control = Some(cache_control.into());
self
}
pub fn override_cache_control(&self) -> Option<&str> {
self.override_cache_control.as_deref()
}
pub fn with_override_content_type(mut self, content_type: &str) -> Self {
self.override_content_type = Some(content_type.into());
self
}
pub fn override_content_type(&self) -> Option<&str> {
self.override_content_type.as_deref()
}
pub fn with_version(mut self, version: &str) -> Self {
self.version = Some(version.to_string());
self
}
pub fn version(&self) -> Option<&str> {
self.version.as_deref()
}
}
impl From<options::StatOptions> for OpStat {
fn from(value: options::StatOptions) -> Self {
Self {
if_match: value.if_match,
if_none_match: value.if_none_match,
if_modified_since: value.if_modified_since,
if_unmodified_since: value.if_unmodified_since,
override_content_type: value.override_content_type,
override_cache_control: value.override_cache_control,
override_content_disposition: value.override_content_disposition,
version: value.version,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct OpWrite {
append: bool,
concurrent: usize,
content_type: Option<String>,
content_disposition: Option<String>,
content_encoding: Option<String>,
cache_control: Option<String>,
if_match: Option<String>,
if_none_match: Option<String>,
if_not_exists: bool,
user_metadata: Option<HashMap<String, String>>,
}
impl OpWrite {
pub fn new() -> Self {
Self::default()
}
pub fn append(&self) -> bool {
self.append
}
pub fn with_append(mut self, append: bool) -> Self {
self.append = append;
self
}
pub fn content_type(&self) -> Option<&str> {
self.content_type.as_deref()
}
pub fn with_content_type(mut self, content_type: &str) -> Self {
self.content_type = Some(content_type.to_string());
self
}
pub fn content_disposition(&self) -> Option<&str> {
self.content_disposition.as_deref()
}
pub fn with_content_disposition(mut self, content_disposition: &str) -> Self {
self.content_disposition = Some(content_disposition.to_string());
self
}
pub fn content_encoding(&self) -> Option<&str> {
self.content_encoding.as_deref()
}
pub fn with_content_encoding(mut self, content_encoding: &str) -> Self {
self.content_encoding = Some(content_encoding.to_string());
self
}
pub fn cache_control(&self) -> Option<&str> {
self.cache_control.as_deref()
}
pub fn with_cache_control(mut self, cache_control: &str) -> Self {
self.cache_control = Some(cache_control.to_string());
self
}
pub fn concurrent(&self) -> usize {
self.concurrent
}
pub fn with_concurrent(mut self, concurrent: usize) -> Self {
self.concurrent = concurrent;
self
}
pub fn with_if_match(mut self, s: &str) -> Self {
self.if_match = Some(s.to_string());
self
}
pub fn if_match(&self) -> Option<&str> {
self.if_match.as_deref()
}
pub fn with_if_none_match(mut self, s: &str) -> Self {
self.if_none_match = Some(s.to_string());
self
}
pub fn if_none_match(&self) -> Option<&str> {
self.if_none_match.as_deref()
}
pub fn with_if_not_exists(mut self, b: bool) -> Self {
self.if_not_exists = b;
self
}
pub fn if_not_exists(&self) -> bool {
self.if_not_exists
}
pub fn with_user_metadata(mut self, metadata: HashMap<String, String>) -> Self {
self.user_metadata = Some(metadata);
self
}
pub fn user_metadata(&self) -> Option<&HashMap<String, String>> {
self.user_metadata.as_ref()
}
}
#[derive(Debug, Clone, Default)]
pub struct OpWriter {
chunk: Option<usize>,
}
impl OpWriter {
pub fn new() -> Self {
Self::default()
}
pub fn chunk(&self) -> Option<usize> {
self.chunk
}
pub fn with_chunk(mut self, chunk: usize) -> Self {
self.chunk = Some(chunk);
self
}
}
impl From<options::WriteOptions> for (OpWrite, OpWriter) {
fn from(value: options::WriteOptions) -> Self {
(
OpWrite {
append: value.append,
concurrent: value.concurrent.max(1),
content_type: value.content_type,
content_disposition: value.content_disposition,
content_encoding: value.content_encoding,
cache_control: value.cache_control,
if_match: value.if_match,
if_none_match: value.if_none_match,
if_not_exists: value.if_not_exists,
user_metadata: value.user_metadata,
},
OpWriter { chunk: value.chunk },
)
}
}
#[derive(Debug, Clone, Default)]
pub struct OpCopy {
if_not_exists: bool,
}
impl OpCopy {
pub fn new() -> Self {
Self::default()
}
pub fn with_if_not_exists(mut self, if_not_exists: bool) -> Self {
self.if_not_exists = if_not_exists;
self
}
pub fn if_not_exists(&self) -> bool {
self.if_not_exists
}
}
#[derive(Debug, Clone, Default)]
pub struct OpRename {}
impl OpRename {
pub fn new() -> Self {
Self::default()
}
}