1use crate::options;
23use crate::raw::*;
24use std::collections::HashMap;
25use std::time::Duration;
26
27#[derive(Debug, Clone, Default)]
31pub struct OpCreateDir {}
32
33impl OpCreateDir {
34 pub fn new() -> Self {
36 Self::default()
37 }
38}
39
40#[derive(Debug, Clone, Default, Eq, Hash, PartialEq)]
44pub struct OpDelete {
45 version: Option<String>,
46}
47
48impl OpDelete {
49 pub fn new() -> Self {
51 Self::default()
52 }
53}
54
55impl OpDelete {
56 pub fn with_version(mut self, version: &str) -> Self {
58 self.version = Some(version.into());
59 self
60 }
61
62 pub fn version(&self) -> Option<&str> {
64 self.version.as_deref()
65 }
66}
67
68impl From<options::DeleteOptions> for OpDelete {
69 fn from(value: options::DeleteOptions) -> Self {
70 Self {
71 version: value.version,
72 }
73 }
74}
75
76#[derive(Debug, Clone, Default)]
80pub struct OpDeleter {}
81
82impl OpDeleter {
83 pub fn new() -> Self {
85 Self::default()
86 }
87}
88
89#[derive(Debug, Clone, Default)]
91pub struct OpList {
92 limit: Option<usize>,
97 start_after: Option<String>,
100 recursive: bool,
107 versions: bool,
115 deleted: bool,
123}
124
125impl OpList {
126 pub fn new() -> Self {
128 Self::default()
129 }
130
131 pub fn with_limit(mut self, limit: usize) -> Self {
133 self.limit = Some(limit);
134 self
135 }
136
137 pub fn limit(&self) -> Option<usize> {
139 self.limit
140 }
141
142 pub fn with_start_after(mut self, start_after: &str) -> Self {
144 self.start_after = Some(start_after.into());
145 self
146 }
147
148 pub fn start_after(&self) -> Option<&str> {
150 self.start_after.as_deref()
151 }
152
153 pub fn with_recursive(mut self, recursive: bool) -> Self {
160 self.recursive = recursive;
161 self
162 }
163
164 pub fn recursive(&self) -> bool {
166 self.recursive
167 }
168
169 #[deprecated(since = "0.53.2", note = "concurrent in list is no-op")]
173 pub fn with_concurrent(self, concurrent: usize) -> Self {
174 let _ = concurrent;
175 self
176 }
177
178 #[deprecated(since = "0.53.2", note = "concurrent in list is no-op")]
180 pub fn concurrent(&self) -> usize {
181 0
182 }
183
184 #[deprecated(since = "0.51.1", note = "use with_versions instead")]
186 pub fn with_version(mut self, version: bool) -> Self {
187 self.versions = version;
188 self
189 }
190
191 pub fn with_versions(mut self, versions: bool) -> Self {
193 self.versions = versions;
194 self
195 }
196
197 #[deprecated(since = "0.51.1", note = "use versions instead")]
199 pub fn version(&self) -> bool {
200 self.versions
201 }
202
203 pub fn versions(&self) -> bool {
205 self.versions
206 }
207
208 pub fn with_deleted(mut self, deleted: bool) -> Self {
210 self.deleted = deleted;
211 self
212 }
213
214 pub fn deleted(&self) -> bool {
216 self.deleted
217 }
218}
219
220impl From<options::ListOptions> for OpList {
221 fn from(value: options::ListOptions) -> Self {
222 Self {
223 limit: value.limit,
224 start_after: value.start_after,
225 recursive: value.recursive,
226 versions: value.versions,
227 deleted: value.deleted,
228 }
229 }
230}
231
232#[derive(Debug, Clone)]
236pub struct OpPresign {
237 expire: Duration,
238
239 op: PresignOperation,
240}
241
242impl OpPresign {
243 pub fn new(op: impl Into<PresignOperation>, expire: Duration) -> Self {
245 Self {
246 op: op.into(),
247 expire,
248 }
249 }
250
251 pub fn operation(&self) -> &PresignOperation {
253 &self.op
254 }
255
256 pub fn expire(&self) -> Duration {
258 self.expire
259 }
260
261 pub fn into_parts(self) -> (Duration, PresignOperation) {
263 (self.expire, self.op)
264 }
265}
266
267#[derive(Debug, Clone)]
269#[non_exhaustive]
270pub enum PresignOperation {
271 Stat(OpStat),
273 Read(OpRead),
275 Write(OpWrite),
277 Delete(OpDelete),
279}
280
281impl From<OpStat> for PresignOperation {
282 fn from(op: OpStat) -> Self {
283 Self::Stat(op)
284 }
285}
286
287impl From<OpRead> for PresignOperation {
288 fn from(v: OpRead) -> Self {
289 Self::Read(v)
290 }
291}
292
293impl From<OpWrite> for PresignOperation {
294 fn from(v: OpWrite) -> Self {
295 Self::Write(v)
296 }
297}
298
299impl From<OpDelete> for PresignOperation {
300 fn from(v: OpDelete) -> Self {
301 Self::Delete(v)
302 }
303}
304
305#[derive(Debug, Clone, Default)]
307pub struct OpRead {
308 range: BytesRange,
309 if_match: Option<String>,
310 if_none_match: Option<String>,
311 if_modified_since: Option<Timestamp>,
312 if_unmodified_since: Option<Timestamp>,
313 override_content_type: Option<String>,
314 override_cache_control: Option<String>,
315 override_content_disposition: Option<String>,
316 version: Option<String>,
317}
318
319impl OpRead {
320 pub fn new() -> Self {
322 Self::default()
323 }
324
325 pub fn with_range(mut self, range: BytesRange) -> Self {
327 self.range = range;
328 self
329 }
330
331 pub fn range(&self) -> BytesRange {
333 self.range
334 }
335
336 pub(crate) fn range_mut(&mut self) -> &mut BytesRange {
338 &mut self.range
339 }
340
341 pub fn with_override_content_disposition(mut self, content_disposition: &str) -> Self {
343 self.override_content_disposition = Some(content_disposition.into());
344 self
345 }
346
347 pub fn override_content_disposition(&self) -> Option<&str> {
350 self.override_content_disposition.as_deref()
351 }
352
353 pub fn with_override_cache_control(mut self, cache_control: &str) -> Self {
355 self.override_cache_control = Some(cache_control.into());
356 self
357 }
358
359 pub fn override_cache_control(&self) -> Option<&str> {
361 self.override_cache_control.as_deref()
362 }
363
364 pub fn with_override_content_type(mut self, content_type: &str) -> Self {
366 self.override_content_type = Some(content_type.into());
367 self
368 }
369
370 pub fn override_content_type(&self) -> Option<&str> {
372 self.override_content_type.as_deref()
373 }
374
375 pub fn with_if_match(mut self, if_match: &str) -> Self {
377 self.if_match = Some(if_match.to_string());
378 self
379 }
380
381 pub fn if_match(&self) -> Option<&str> {
383 self.if_match.as_deref()
384 }
385
386 pub fn with_if_none_match(mut self, if_none_match: &str) -> Self {
388 self.if_none_match = Some(if_none_match.to_string());
389 self
390 }
391
392 pub fn if_none_match(&self) -> Option<&str> {
394 self.if_none_match.as_deref()
395 }
396
397 pub fn with_if_modified_since(mut self, v: Timestamp) -> Self {
399 self.if_modified_since = Some(v);
400 self
401 }
402
403 pub fn if_modified_since(&self) -> Option<Timestamp> {
405 self.if_modified_since
406 }
407
408 pub fn with_if_unmodified_since(mut self, v: Timestamp) -> Self {
410 self.if_unmodified_since = Some(v);
411 self
412 }
413
414 pub fn if_unmodified_since(&self) -> Option<Timestamp> {
416 self.if_unmodified_since
417 }
418
419 pub fn with_version(mut self, version: &str) -> Self {
421 self.version = Some(version.to_string());
422 self
423 }
424
425 pub fn version(&self) -> Option<&str> {
427 self.version.as_deref()
428 }
429}
430
431#[derive(Debug, Clone)]
433pub struct OpReader {
434 concurrent: usize,
436 chunk: Option<usize>,
438 gap: Option<usize>,
440 prefetch: usize,
442}
443
444impl Default for OpReader {
445 fn default() -> Self {
446 Self {
447 concurrent: 1,
448 chunk: None,
449 gap: None,
450 prefetch: 0,
451 }
452 }
453}
454
455impl OpReader {
456 pub fn new() -> Self {
458 Self::default()
459 }
460
461 pub fn with_concurrent(mut self, concurrent: usize) -> Self {
463 self.concurrent = concurrent.max(1);
464 self
465 }
466
467 pub fn concurrent(&self) -> usize {
469 self.concurrent
470 }
471
472 pub fn with_chunk(mut self, chunk: usize) -> Self {
474 self.chunk = Some(chunk.max(1));
475 self
476 }
477
478 pub fn chunk(&self) -> Option<usize> {
480 self.chunk
481 }
482
483 pub fn with_gap(mut self, gap: usize) -> Self {
485 self.gap = Some(gap.max(1));
486 self
487 }
488
489 pub fn gap(&self) -> Option<usize> {
491 self.gap
492 }
493
494 pub fn with_prefetch(mut self, prefetch: usize) -> Self {
496 self.prefetch = prefetch;
497 self
498 }
499
500 pub fn prefetch(&self) -> usize {
502 self.prefetch
503 }
504}
505
506impl From<options::ReadOptions> for (OpRead, OpReader) {
507 fn from(value: options::ReadOptions) -> Self {
508 (
509 OpRead {
510 range: value.range,
511 if_match: value.if_match,
512 if_none_match: value.if_none_match,
513 if_modified_since: value.if_modified_since,
514 if_unmodified_since: value.if_unmodified_since,
515 override_content_type: value.override_content_type,
516 override_cache_control: value.override_cache_control,
517 override_content_disposition: value.override_content_disposition,
518 version: value.version,
519 },
520 OpReader {
521 concurrent: value.concurrent.max(1),
523 chunk: value.chunk,
524 gap: value.gap,
525 prefetch: 0,
526 },
527 )
528 }
529}
530
531impl From<options::ReaderOptions> for (OpRead, OpReader) {
532 fn from(value: options::ReaderOptions) -> Self {
533 (
534 OpRead {
535 range: BytesRange::default(),
536 if_match: value.if_match,
537 if_none_match: value.if_none_match,
538 if_modified_since: value.if_modified_since,
539 if_unmodified_since: value.if_unmodified_since,
540 override_content_type: None,
541 override_cache_control: None,
542 override_content_disposition: None,
543 version: value.version,
544 },
545 OpReader {
546 concurrent: value.concurrent.max(1),
548 chunk: value.chunk,
549 gap: value.gap,
550 prefetch: value.prefetch,
551 },
552 )
553 }
554}
555
556#[derive(Debug, Clone, Default)]
558pub struct OpStat {
559 if_match: Option<String>,
560 if_none_match: Option<String>,
561 if_modified_since: Option<Timestamp>,
562 if_unmodified_since: Option<Timestamp>,
563 override_content_type: Option<String>,
564 override_cache_control: Option<String>,
565 override_content_disposition: Option<String>,
566 version: Option<String>,
567}
568
569impl OpStat {
570 pub fn new() -> Self {
572 Self::default()
573 }
574
575 pub fn with_if_match(mut self, if_match: &str) -> Self {
577 self.if_match = Some(if_match.to_string());
578 self
579 }
580
581 pub fn if_match(&self) -> Option<&str> {
583 self.if_match.as_deref()
584 }
585
586 pub fn with_if_none_match(mut self, if_none_match: &str) -> Self {
588 self.if_none_match = Some(if_none_match.to_string());
589 self
590 }
591
592 pub fn if_none_match(&self) -> Option<&str> {
594 self.if_none_match.as_deref()
595 }
596
597 pub fn with_if_modified_since(mut self, v: Timestamp) -> Self {
599 self.if_modified_since = Some(v);
600 self
601 }
602
603 pub fn if_modified_since(&self) -> Option<Timestamp> {
605 self.if_modified_since
606 }
607
608 pub fn with_if_unmodified_since(mut self, v: Timestamp) -> Self {
610 self.if_unmodified_since = Some(v);
611 self
612 }
613
614 pub fn if_unmodified_since(&self) -> Option<Timestamp> {
616 self.if_unmodified_since
617 }
618
619 pub fn with_override_content_disposition(mut self, content_disposition: &str) -> Self {
621 self.override_content_disposition = Some(content_disposition.into());
622 self
623 }
624
625 pub fn override_content_disposition(&self) -> Option<&str> {
628 self.override_content_disposition.as_deref()
629 }
630
631 pub fn with_override_cache_control(mut self, cache_control: &str) -> Self {
633 self.override_cache_control = Some(cache_control.into());
634 self
635 }
636
637 pub fn override_cache_control(&self) -> Option<&str> {
639 self.override_cache_control.as_deref()
640 }
641
642 pub fn with_override_content_type(mut self, content_type: &str) -> Self {
644 self.override_content_type = Some(content_type.into());
645 self
646 }
647
648 pub fn override_content_type(&self) -> Option<&str> {
650 self.override_content_type.as_deref()
651 }
652
653 pub fn with_version(mut self, version: &str) -> Self {
655 self.version = Some(version.to_string());
656 self
657 }
658
659 pub fn version(&self) -> Option<&str> {
661 self.version.as_deref()
662 }
663}
664
665impl From<options::StatOptions> for OpStat {
666 fn from(value: options::StatOptions) -> Self {
667 Self {
668 if_match: value.if_match,
669 if_none_match: value.if_none_match,
670 if_modified_since: value.if_modified_since,
671 if_unmodified_since: value.if_unmodified_since,
672 override_content_type: value.override_content_type,
673 override_cache_control: value.override_cache_control,
674 override_content_disposition: value.override_content_disposition,
675 version: value.version,
676 }
677 }
678}
679
680#[derive(Debug, Clone, Default)]
682pub struct OpWrite {
683 append: bool,
684 concurrent: usize,
685 content_type: Option<String>,
686 content_disposition: Option<String>,
687 content_encoding: Option<String>,
688 cache_control: Option<String>,
689 if_match: Option<String>,
690 if_none_match: Option<String>,
691 if_not_exists: bool,
692 user_metadata: Option<HashMap<String, String>>,
693}
694
695impl OpWrite {
696 pub fn new() -> Self {
700 Self::default()
701 }
702
703 pub fn append(&self) -> bool {
707 self.append
708 }
709
710 pub fn with_append(mut self, append: bool) -> Self {
718 self.append = append;
719 self
720 }
721
722 pub fn content_type(&self) -> Option<&str> {
724 self.content_type.as_deref()
725 }
726
727 pub fn with_content_type(mut self, content_type: &str) -> Self {
729 self.content_type = Some(content_type.to_string());
730 self
731 }
732
733 pub fn content_disposition(&self) -> Option<&str> {
735 self.content_disposition.as_deref()
736 }
737
738 pub fn with_content_disposition(mut self, content_disposition: &str) -> Self {
740 self.content_disposition = Some(content_disposition.to_string());
741 self
742 }
743
744 pub fn content_encoding(&self) -> Option<&str> {
746 self.content_encoding.as_deref()
747 }
748
749 pub fn with_content_encoding(mut self, content_encoding: &str) -> Self {
751 self.content_encoding = Some(content_encoding.to_string());
752 self
753 }
754
755 pub fn cache_control(&self) -> Option<&str> {
757 self.cache_control.as_deref()
758 }
759
760 pub fn with_cache_control(mut self, cache_control: &str) -> Self {
762 self.cache_control = Some(cache_control.to_string());
763 self
764 }
765
766 pub fn concurrent(&self) -> usize {
768 self.concurrent
769 }
770
771 pub fn with_concurrent(mut self, concurrent: usize) -> Self {
773 self.concurrent = concurrent;
774 self
775 }
776
777 pub fn with_if_match(mut self, s: &str) -> Self {
779 self.if_match = Some(s.to_string());
780 self
781 }
782
783 pub fn if_match(&self) -> Option<&str> {
785 self.if_match.as_deref()
786 }
787
788 pub fn with_if_none_match(mut self, s: &str) -> Self {
790 self.if_none_match = Some(s.to_string());
791 self
792 }
793
794 pub fn if_none_match(&self) -> Option<&str> {
796 self.if_none_match.as_deref()
797 }
798
799 pub fn with_if_not_exists(mut self, b: bool) -> Self {
801 self.if_not_exists = b;
802 self
803 }
804
805 pub fn if_not_exists(&self) -> bool {
807 self.if_not_exists
808 }
809
810 pub fn with_user_metadata(mut self, metadata: HashMap<String, String>) -> Self {
812 self.user_metadata = Some(metadata);
813 self
814 }
815
816 pub fn user_metadata(&self) -> Option<&HashMap<String, String>> {
818 self.user_metadata.as_ref()
819 }
820}
821
822#[derive(Debug, Clone, Default)]
824pub struct OpWriter {
825 chunk: Option<usize>,
826}
827
828impl OpWriter {
829 pub fn new() -> Self {
831 Self::default()
832 }
833
834 pub fn chunk(&self) -> Option<usize> {
838 self.chunk
839 }
840
841 pub fn with_chunk(mut self, chunk: usize) -> Self {
851 self.chunk = Some(chunk);
852 self
853 }
854}
855
856impl From<options::WriteOptions> for (OpWrite, OpWriter) {
857 fn from(value: options::WriteOptions) -> Self {
858 (
859 OpWrite {
860 append: value.append,
861 concurrent: value.concurrent.max(1),
863 content_type: value.content_type,
864 content_disposition: value.content_disposition,
865 content_encoding: value.content_encoding,
866 cache_control: value.cache_control,
867 if_match: value.if_match,
868 if_none_match: value.if_none_match,
869 if_not_exists: value.if_not_exists,
870 user_metadata: value.user_metadata,
871 },
872 OpWriter { chunk: value.chunk },
873 )
874 }
875}
876
877#[derive(Debug, Clone, Default)]
879pub struct OpCopy {
880 if_not_exists: bool,
881}
882
883impl OpCopy {
884 pub fn new() -> Self {
886 Self::default()
887 }
888
889 pub fn with_if_not_exists(mut self, if_not_exists: bool) -> Self {
894 self.if_not_exists = if_not_exists;
895 self
896 }
897
898 pub fn if_not_exists(&self) -> bool {
900 self.if_not_exists
901 }
902}
903
904#[derive(Debug, Clone, Default)]
906pub struct OpRename {}
907
908impl OpRename {
909 pub fn new() -> Self {
911 Self::default()
912 }
913}