1use crate::BytesRange;
23use crate::options;
24use crate::raw::*;
25
26use std::collections::HashMap;
27
28#[derive(Debug, Clone, Default)]
32pub struct OpCreateDir {}
33
34impl OpCreateDir {
35 pub fn new() -> Self {
37 Self::default()
38 }
39}
40
41#[derive(Debug, Clone, Default, Eq, Hash, PartialEq)]
45pub struct OpDelete {
46 version: Option<String>,
48
49 recursive: bool,
51}
52
53impl OpDelete {
54 pub fn new() -> Self {
56 Self::default()
57 }
58}
59
60impl OpDelete {
61 pub fn with_version(mut self, version: &str) -> Self {
63 self.version = Some(version.into());
64 self
65 }
66
67 pub fn with_recursive(mut self, recursive: bool) -> Self {
69 self.recursive = recursive;
70 self
71 }
72
73 pub fn version(&self) -> Option<&str> {
75 self.version.as_deref()
76 }
77
78 pub fn recursive(&self) -> bool {
80 self.recursive
81 }
82}
83
84impl From<options::DeleteOptions> for OpDelete {
85 fn from(value: options::DeleteOptions) -> Self {
86 Self {
87 version: value.version,
88 recursive: value.recursive,
89 }
90 }
91}
92
93#[derive(Debug, Clone, Default)]
97pub struct OpDeleter {}
98
99impl OpDeleter {
100 pub fn new() -> Self {
102 Self::default()
103 }
104}
105
106#[derive(Debug, Clone, Default)]
108pub struct OpList {
109 limit: Option<usize>,
113
114 start_after: Option<String>,
116
117 recursive: bool,
126
127 versions: bool,
135
136 deleted: bool,
144}
145
146impl OpList {
147 pub fn new() -> Self {
149 Self::default()
150 }
151
152 pub fn with_limit(mut self, limit: usize) -> Self {
154 self.limit = Some(limit);
155 self
156 }
157
158 pub fn limit(&self) -> Option<usize> {
160 self.limit
161 }
162
163 pub fn with_start_after(mut self, start_after: &str) -> Self {
165 self.start_after = Some(start_after.into());
166 self
167 }
168
169 pub fn start_after(&self) -> Option<&str> {
171 self.start_after.as_deref()
172 }
173
174 pub fn with_recursive(mut self, recursive: bool) -> Self {
183 self.recursive = recursive;
184 self
185 }
186
187 pub fn recursive(&self) -> bool {
189 self.recursive
190 }
191
192 #[deprecated(since = "0.53.2", note = "concurrent in list is no-op")]
196 pub fn with_concurrent(self, concurrent: usize) -> Self {
197 let _ = concurrent;
198 self
199 }
200
201 #[deprecated(since = "0.53.2", note = "concurrent in list is no-op")]
203 pub fn concurrent(&self) -> usize {
204 0
205 }
206
207 pub fn with_versions(mut self, versions: bool) -> Self {
209 self.versions = versions;
210 self
211 }
212
213 pub fn versions(&self) -> bool {
215 self.versions
216 }
217
218 pub fn with_deleted(mut self, deleted: bool) -> Self {
220 self.deleted = deleted;
221 self
222 }
223
224 pub fn deleted(&self) -> bool {
226 self.deleted
227 }
228}
229
230impl From<options::ListOptions> for OpList {
231 fn from(value: options::ListOptions) -> Self {
232 Self {
233 limit: value.limit,
234 start_after: value.start_after,
235 recursive: value.recursive,
236 versions: value.versions,
237 deleted: value.deleted,
238 }
239 }
240}
241
242#[derive(Debug, Clone)]
246pub struct OpPresign {
247 expire: Duration,
248
249 op: PresignOperation,
250}
251
252impl OpPresign {
253 pub fn new(op: impl Into<PresignOperation>, expire: Duration) -> Self {
255 Self {
256 op: op.into(),
257 expire,
258 }
259 }
260
261 pub fn operation(&self) -> &PresignOperation {
263 &self.op
264 }
265
266 pub fn expire(&self) -> Duration {
268 self.expire
269 }
270
271 pub fn into_parts(self) -> (Duration, PresignOperation) {
273 (self.expire, self.op)
274 }
275}
276
277#[derive(Debug, Clone)]
279#[non_exhaustive]
280pub enum PresignOperation {
281 Stat(OpStat),
283 Read(BytesRange, OpRead),
285 Write(OpWrite),
287 Delete(OpDelete),
289}
290
291impl From<OpStat> for PresignOperation {
292 fn from(op: OpStat) -> Self {
293 Self::Stat(op)
294 }
295}
296
297impl From<OpRead> for PresignOperation {
298 fn from(v: OpRead) -> Self {
299 Self::Read(BytesRange::default(), v)
300 }
301}
302
303impl From<OpWrite> for PresignOperation {
304 fn from(v: OpWrite) -> Self {
305 Self::Write(v)
306 }
307}
308
309impl From<OpDelete> for PresignOperation {
310 fn from(v: OpDelete) -> Self {
311 Self::Delete(v)
312 }
313}
314
315#[derive(Debug, Clone, Default)]
317pub struct OpRead {
318 if_match: Option<String>,
319 if_none_match: Option<String>,
320 if_modified_since: Option<Timestamp>,
321 if_unmodified_since: Option<Timestamp>,
322 override_content_type: Option<String>,
323 override_cache_control: Option<String>,
324 override_content_disposition: Option<String>,
325 version: Option<String>,
326 content_length_hint: Option<u64>,
327}
328
329impl OpRead {
330 pub fn new() -> Self {
332 Self::default()
333 }
334
335 pub fn with_override_content_disposition(mut self, content_disposition: &str) -> Self {
337 self.override_content_disposition = Some(content_disposition.into());
338 self
339 }
340
341 pub fn override_content_disposition(&self) -> Option<&str> {
344 self.override_content_disposition.as_deref()
345 }
346
347 pub fn with_override_cache_control(mut self, cache_control: &str) -> Self {
349 self.override_cache_control = Some(cache_control.into());
350 self
351 }
352
353 pub fn override_cache_control(&self) -> Option<&str> {
355 self.override_cache_control.as_deref()
356 }
357
358 pub fn with_override_content_type(mut self, content_type: &str) -> Self {
360 self.override_content_type = Some(content_type.into());
361 self
362 }
363
364 pub fn override_content_type(&self) -> Option<&str> {
366 self.override_content_type.as_deref()
367 }
368
369 pub fn with_if_match(mut self, if_match: &str) -> Self {
371 self.if_match = Some(if_match.to_string());
372 self
373 }
374
375 pub fn if_match(&self) -> Option<&str> {
377 self.if_match.as_deref()
378 }
379
380 pub fn with_if_none_match(mut self, if_none_match: &str) -> Self {
382 self.if_none_match = Some(if_none_match.to_string());
383 self
384 }
385
386 pub fn if_none_match(&self) -> Option<&str> {
388 self.if_none_match.as_deref()
389 }
390
391 pub fn with_if_modified_since(mut self, v: Timestamp) -> Self {
393 self.if_modified_since = Some(v);
394 self
395 }
396
397 pub fn if_modified_since(&self) -> Option<Timestamp> {
399 self.if_modified_since
400 }
401
402 pub fn with_if_unmodified_since(mut self, v: Timestamp) -> Self {
404 self.if_unmodified_since = Some(v);
405 self
406 }
407
408 pub fn if_unmodified_since(&self) -> Option<Timestamp> {
410 self.if_unmodified_since
411 }
412
413 pub fn with_version(mut self, version: &str) -> Self {
415 self.version = Some(version.to_string());
416 self
417 }
418
419 pub fn version(&self) -> Option<&str> {
421 self.version.as_deref()
422 }
423
424 pub(crate) fn content_length_hint(&self) -> Option<u64> {
425 self.content_length_hint
426 }
427}
428
429#[derive(Debug, Clone)]
431pub struct OpReader {
432 concurrent: usize,
434 chunk: Option<usize>,
436 gap: Option<usize>,
438 prefetch: usize,
440}
441
442impl Default for OpReader {
443 fn default() -> Self {
444 Self {
445 concurrent: 1,
446 chunk: None,
447 gap: None,
448 prefetch: 0,
449 }
450 }
451}
452
453impl OpReader {
454 pub fn new() -> Self {
456 Self::default()
457 }
458
459 pub fn with_concurrent(mut self, concurrent: usize) -> Self {
461 self.concurrent = concurrent.max(1);
462 self
463 }
464
465 pub fn concurrent(&self) -> usize {
467 self.concurrent
468 }
469
470 pub fn with_chunk(mut self, chunk: usize) -> Self {
472 self.chunk = Some(chunk.max(1));
473 self
474 }
475
476 pub fn chunk(&self) -> Option<usize> {
478 self.chunk
479 }
480
481 pub fn with_gap(mut self, gap: usize) -> Self {
486 self.gap = Some(gap);
487 self
488 }
489
490 pub fn gap(&self) -> Option<usize> {
492 self.gap
493 }
494
495 pub fn with_prefetch(mut self, prefetch: usize) -> Self {
497 self.prefetch = prefetch;
498 self
499 }
500
501 pub fn prefetch(&self) -> usize {
503 self.prefetch
504 }
505}
506
507impl From<options::ReadOptions> for (BytesRange, OpRead, OpReader) {
508 fn from(value: options::ReadOptions) -> Self {
509 (
510 value.range,
511 OpRead {
512 if_match: value.if_match,
513 if_none_match: value.if_none_match,
514 if_modified_since: value.if_modified_since,
515 if_unmodified_since: value.if_unmodified_since,
516 override_content_type: value.override_content_type,
517 override_cache_control: value.override_cache_control,
518 override_content_disposition: value.override_content_disposition,
519 version: value.version,
520 content_length_hint: value.content_length_hint,
521 },
522 OpReader {
523 concurrent: value.concurrent.max(1),
525 chunk: value.chunk,
526 gap: value.gap,
527 prefetch: 0,
528 },
529 )
530 }
531}
532
533impl From<options::ReaderOptions> for (OpRead, OpReader) {
534 fn from(value: options::ReaderOptions) -> Self {
535 (
536 OpRead {
537 if_match: value.if_match,
538 if_none_match: value.if_none_match,
539 if_modified_since: value.if_modified_since,
540 if_unmodified_since: value.if_unmodified_since,
541 override_content_type: None,
542 override_cache_control: None,
543 override_content_disposition: None,
544 version: value.version,
545 content_length_hint: value.content_length_hint,
546 },
547 OpReader {
548 concurrent: value.concurrent.max(1),
550 chunk: value.chunk,
551 gap: value.gap,
552 prefetch: value.prefetch,
553 },
554 )
555 }
556}
557
558#[derive(Debug, Clone, Default)]
560pub struct OpStat {
561 if_match: Option<String>,
562 if_none_match: Option<String>,
563 if_modified_since: Option<Timestamp>,
564 if_unmodified_since: Option<Timestamp>,
565 override_content_type: Option<String>,
566 override_cache_control: Option<String>,
567 override_content_disposition: Option<String>,
568 version: Option<String>,
569}
570
571impl OpStat {
572 pub fn new() -> Self {
574 Self::default()
575 }
576
577 pub fn with_if_match(mut self, if_match: &str) -> Self {
579 self.if_match = Some(if_match.to_string());
580 self
581 }
582
583 pub fn if_match(&self) -> Option<&str> {
585 self.if_match.as_deref()
586 }
587
588 pub fn with_if_none_match(mut self, if_none_match: &str) -> Self {
590 self.if_none_match = Some(if_none_match.to_string());
591 self
592 }
593
594 pub fn if_none_match(&self) -> Option<&str> {
596 self.if_none_match.as_deref()
597 }
598
599 pub fn with_if_modified_since(mut self, v: Timestamp) -> Self {
601 self.if_modified_since = Some(v);
602 self
603 }
604
605 pub fn if_modified_since(&self) -> Option<Timestamp> {
607 self.if_modified_since
608 }
609
610 pub fn with_if_unmodified_since(mut self, v: Timestamp) -> Self {
612 self.if_unmodified_since = Some(v);
613 self
614 }
615
616 pub fn if_unmodified_since(&self) -> Option<Timestamp> {
618 self.if_unmodified_since
619 }
620
621 pub fn with_override_content_disposition(mut self, content_disposition: &str) -> Self {
623 self.override_content_disposition = Some(content_disposition.into());
624 self
625 }
626
627 pub fn override_content_disposition(&self) -> Option<&str> {
630 self.override_content_disposition.as_deref()
631 }
632
633 pub fn with_override_cache_control(mut self, cache_control: &str) -> Self {
635 self.override_cache_control = Some(cache_control.into());
636 self
637 }
638
639 pub fn override_cache_control(&self) -> Option<&str> {
641 self.override_cache_control.as_deref()
642 }
643
644 pub fn with_override_content_type(mut self, content_type: &str) -> Self {
646 self.override_content_type = Some(content_type.into());
647 self
648 }
649
650 pub fn override_content_type(&self) -> Option<&str> {
652 self.override_content_type.as_deref()
653 }
654
655 pub fn with_version(mut self, version: &str) -> Self {
657 self.version = Some(version.to_string());
658 self
659 }
660
661 pub fn version(&self) -> Option<&str> {
663 self.version.as_deref()
664 }
665}
666
667impl From<options::StatOptions> for OpStat {
668 fn from(value: options::StatOptions) -> Self {
669 Self {
670 if_match: value.if_match,
671 if_none_match: value.if_none_match,
672 if_modified_since: value.if_modified_since,
673 if_unmodified_since: value.if_unmodified_since,
674 override_content_type: value.override_content_type,
675 override_cache_control: value.override_cache_control,
676 override_content_disposition: value.override_content_disposition,
677 version: value.version,
678 }
679 }
680}
681
682#[derive(Debug, Clone, Default)]
684pub struct OpWrite {
685 append: bool,
686 concurrent: usize,
687 content_type: Option<String>,
688 content_disposition: Option<String>,
689 content_encoding: Option<String>,
690 cache_control: Option<String>,
691 if_match: Option<String>,
692 if_none_match: Option<String>,
693 if_not_exists: bool,
694 user_metadata: Option<HashMap<String, String>>,
695}
696
697impl OpWrite {
698 pub fn new() -> Self {
702 Self::default()
703 }
704
705 pub fn append(&self) -> bool {
709 self.append
710 }
711
712 pub fn with_append(mut self, append: bool) -> Self {
720 self.append = append;
721 self
722 }
723
724 pub fn content_type(&self) -> Option<&str> {
726 self.content_type.as_deref()
727 }
728
729 pub fn with_content_type(mut self, content_type: &str) -> Self {
731 self.content_type = Some(content_type.to_string());
732 self
733 }
734
735 pub fn content_disposition(&self) -> Option<&str> {
737 self.content_disposition.as_deref()
738 }
739
740 pub fn with_content_disposition(mut self, content_disposition: &str) -> Self {
742 self.content_disposition = Some(content_disposition.to_string());
743 self
744 }
745
746 pub fn content_encoding(&self) -> Option<&str> {
748 self.content_encoding.as_deref()
749 }
750
751 pub fn with_content_encoding(mut self, content_encoding: &str) -> Self {
753 self.content_encoding = Some(content_encoding.to_string());
754 self
755 }
756
757 pub fn cache_control(&self) -> Option<&str> {
759 self.cache_control.as_deref()
760 }
761
762 pub fn with_cache_control(mut self, cache_control: &str) -> Self {
764 self.cache_control = Some(cache_control.to_string());
765 self
766 }
767
768 pub fn concurrent(&self) -> usize {
770 self.concurrent
771 }
772
773 pub fn with_concurrent(mut self, concurrent: usize) -> Self {
775 self.concurrent = concurrent;
776 self
777 }
778
779 pub fn with_if_match(mut self, s: &str) -> Self {
781 self.if_match = Some(s.to_string());
782 self
783 }
784
785 pub fn if_match(&self) -> Option<&str> {
787 self.if_match.as_deref()
788 }
789
790 pub fn with_if_none_match(mut self, s: &str) -> Self {
792 self.if_none_match = Some(s.to_string());
793 self
794 }
795
796 pub fn if_none_match(&self) -> Option<&str> {
798 self.if_none_match.as_deref()
799 }
800
801 pub fn with_if_not_exists(mut self, b: bool) -> Self {
803 self.if_not_exists = b;
804 self
805 }
806
807 pub fn if_not_exists(&self) -> bool {
809 self.if_not_exists
810 }
811
812 pub fn with_user_metadata(mut self, metadata: HashMap<String, String>) -> Self {
814 self.user_metadata = Some(metadata);
815 self
816 }
817
818 pub fn user_metadata(&self) -> Option<&HashMap<String, String>> {
820 self.user_metadata.as_ref()
821 }
822}
823
824#[derive(Debug, Clone, Default)]
826pub struct OpWriter {
827 chunk: Option<usize>,
828}
829
830impl OpWriter {
831 pub fn new() -> Self {
833 Self::default()
834 }
835
836 pub fn chunk(&self) -> Option<usize> {
840 self.chunk
841 }
842
843 pub fn with_chunk(mut self, chunk: usize) -> Self {
853 self.chunk = Some(chunk);
854 self
855 }
856}
857
858impl From<options::WriteOptions> for (OpWrite, OpWriter) {
859 fn from(value: options::WriteOptions) -> Self {
860 (
861 OpWrite {
862 append: value.append,
863 concurrent: value.concurrent.max(1),
865 content_type: value.content_type,
866 content_disposition: value.content_disposition,
867 content_encoding: value.content_encoding,
868 cache_control: value.cache_control,
869 if_match: value.if_match,
870 if_none_match: value.if_none_match,
871 if_not_exists: value.if_not_exists,
872 user_metadata: value.user_metadata,
873 },
874 OpWriter { chunk: value.chunk },
875 )
876 }
877}
878
879#[derive(Debug, Clone, Default)]
881pub struct OpCopy {
882 if_not_exists: bool,
883 if_match: Option<String>,
884 source_version: Option<String>,
885}
886
887impl OpCopy {
888 pub fn new() -> Self {
890 Self::default()
891 }
892
893 pub fn with_if_not_exists(mut self, if_not_exists: bool) -> Self {
898 self.if_not_exists = if_not_exists;
899 self
900 }
901
902 pub fn if_not_exists(&self) -> bool {
904 self.if_not_exists
905 }
906
907 pub fn with_if_match(mut self, if_match: impl Into<String>) -> Self {
912 self.if_match = Some(if_match.into());
913 self
914 }
915
916 pub fn if_match(&self) -> Option<&str> {
918 self.if_match.as_deref()
919 }
920
921 pub fn with_source_version(mut self, version: impl Into<String>) -> Self {
925 self.source_version = Some(version.into());
926 self
927 }
928
929 pub fn source_version(&self) -> Option<&str> {
931 self.source_version.as_deref()
932 }
933}
934
935#[derive(Debug, Clone, Default)]
937pub struct OpCopier {
938 concurrent: usize,
939 chunk: Option<usize>,
940 source_content_length_hint: Option<u64>,
941}
942
943impl OpCopier {
944 pub fn new() -> Self {
946 Self::default()
947 }
948
949 pub fn with_concurrent(mut self, concurrent: usize) -> Self {
951 self.concurrent = concurrent.max(1);
952 self
953 }
954
955 pub fn concurrent(&self) -> usize {
957 self.concurrent.max(1)
958 }
959
960 pub fn with_chunk(mut self, chunk: usize) -> Self {
962 self.chunk = Some(chunk);
963 self
964 }
965
966 pub fn chunk(&self) -> Option<usize> {
968 self.chunk
969 }
970
971 pub fn with_source_content_length_hint(mut self, content_length: u64) -> Self {
973 self.source_content_length_hint = Some(content_length);
974 self
975 }
976
977 pub fn source_content_length_hint(&self) -> Option<u64> {
979 self.source_content_length_hint
980 }
981}
982
983impl From<options::CopyOptions> for (OpCopy, OpCopier) {
984 fn from(value: options::CopyOptions) -> Self {
985 (
986 OpCopy {
987 if_not_exists: value.if_not_exists,
988 if_match: value.if_match,
989 source_version: value.source_version,
990 },
991 OpCopier {
992 concurrent: value.concurrent.max(1),
993 chunk: value.chunk,
994 source_content_length_hint: value.source_content_length_hint,
995 },
996 )
997 }
998}
999
1000#[derive(Debug, Clone, Default)]
1002pub struct OpRename {
1003 if_not_exists: bool,
1008}
1009
1010impl OpRename {
1011 pub fn new() -> Self {
1013 Self::default()
1014 }
1015
1016 pub fn with_if_not_exists(mut self, if_not_exists: bool) -> Self {
1027 self.if_not_exists = if_not_exists;
1028 self
1029 }
1030
1031 pub fn if_not_exists(&self) -> bool {
1033 self.if_not_exists
1034 }
1035}
1036
1037impl From<options::RenameOptions> for OpRename {
1038 fn from(value: options::RenameOptions) -> Self {
1039 Self {
1040 if_not_exists: value.if_not_exists,
1041 }
1042 }
1043}