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 {
483 self.gap = Some(gap.max(1));
484 self
485 }
486
487 pub fn gap(&self) -> Option<usize> {
489 self.gap
490 }
491
492 pub fn with_prefetch(mut self, prefetch: usize) -> Self {
494 self.prefetch = prefetch;
495 self
496 }
497
498 pub fn prefetch(&self) -> usize {
500 self.prefetch
501 }
502}
503
504impl From<options::ReadOptions> for (BytesRange, OpRead, OpReader) {
505 fn from(value: options::ReadOptions) -> Self {
506 (
507 value.range,
508 OpRead {
509 if_match: value.if_match,
510 if_none_match: value.if_none_match,
511 if_modified_since: value.if_modified_since,
512 if_unmodified_since: value.if_unmodified_since,
513 override_content_type: value.override_content_type,
514 override_cache_control: value.override_cache_control,
515 override_content_disposition: value.override_content_disposition,
516 version: value.version,
517 content_length_hint: value.content_length_hint,
518 },
519 OpReader {
520 concurrent: value.concurrent.max(1),
522 chunk: value.chunk,
523 gap: value.gap,
524 prefetch: 0,
525 },
526 )
527 }
528}
529
530impl From<options::ReaderOptions> for (OpRead, OpReader) {
531 fn from(value: options::ReaderOptions) -> Self {
532 (
533 OpRead {
534 if_match: value.if_match,
535 if_none_match: value.if_none_match,
536 if_modified_since: value.if_modified_since,
537 if_unmodified_since: value.if_unmodified_since,
538 override_content_type: None,
539 override_cache_control: None,
540 override_content_disposition: None,
541 version: value.version,
542 content_length_hint: value.content_length_hint,
543 },
544 OpReader {
545 concurrent: value.concurrent.max(1),
547 chunk: value.chunk,
548 gap: value.gap,
549 prefetch: value.prefetch,
550 },
551 )
552 }
553}
554
555#[derive(Debug, Clone, Default)]
557pub struct OpStat {
558 if_match: Option<String>,
559 if_none_match: Option<String>,
560 if_modified_since: Option<Timestamp>,
561 if_unmodified_since: Option<Timestamp>,
562 override_content_type: Option<String>,
563 override_cache_control: Option<String>,
564 override_content_disposition: Option<String>,
565 version: Option<String>,
566}
567
568impl OpStat {
569 pub fn new() -> Self {
571 Self::default()
572 }
573
574 pub fn with_if_match(mut self, if_match: &str) -> Self {
576 self.if_match = Some(if_match.to_string());
577 self
578 }
579
580 pub fn if_match(&self) -> Option<&str> {
582 self.if_match.as_deref()
583 }
584
585 pub fn with_if_none_match(mut self, if_none_match: &str) -> Self {
587 self.if_none_match = Some(if_none_match.to_string());
588 self
589 }
590
591 pub fn if_none_match(&self) -> Option<&str> {
593 self.if_none_match.as_deref()
594 }
595
596 pub fn with_if_modified_since(mut self, v: Timestamp) -> Self {
598 self.if_modified_since = Some(v);
599 self
600 }
601
602 pub fn if_modified_since(&self) -> Option<Timestamp> {
604 self.if_modified_since
605 }
606
607 pub fn with_if_unmodified_since(mut self, v: Timestamp) -> Self {
609 self.if_unmodified_since = Some(v);
610 self
611 }
612
613 pub fn if_unmodified_since(&self) -> Option<Timestamp> {
615 self.if_unmodified_since
616 }
617
618 pub fn with_override_content_disposition(mut self, content_disposition: &str) -> Self {
620 self.override_content_disposition = Some(content_disposition.into());
621 self
622 }
623
624 pub fn override_content_disposition(&self) -> Option<&str> {
627 self.override_content_disposition.as_deref()
628 }
629
630 pub fn with_override_cache_control(mut self, cache_control: &str) -> Self {
632 self.override_cache_control = Some(cache_control.into());
633 self
634 }
635
636 pub fn override_cache_control(&self) -> Option<&str> {
638 self.override_cache_control.as_deref()
639 }
640
641 pub fn with_override_content_type(mut self, content_type: &str) -> Self {
643 self.override_content_type = Some(content_type.into());
644 self
645 }
646
647 pub fn override_content_type(&self) -> Option<&str> {
649 self.override_content_type.as_deref()
650 }
651
652 pub fn with_version(mut self, version: &str) -> Self {
654 self.version = Some(version.to_string());
655 self
656 }
657
658 pub fn version(&self) -> Option<&str> {
660 self.version.as_deref()
661 }
662}
663
664impl From<options::StatOptions> for OpStat {
665 fn from(value: options::StatOptions) -> Self {
666 Self {
667 if_match: value.if_match,
668 if_none_match: value.if_none_match,
669 if_modified_since: value.if_modified_since,
670 if_unmodified_since: value.if_unmodified_since,
671 override_content_type: value.override_content_type,
672 override_cache_control: value.override_cache_control,
673 override_content_disposition: value.override_content_disposition,
674 version: value.version,
675 }
676 }
677}
678
679#[derive(Debug, Clone, Default)]
681pub struct OpWrite {
682 append: bool,
683 concurrent: usize,
684 content_type: Option<String>,
685 content_disposition: Option<String>,
686 content_encoding: Option<String>,
687 cache_control: Option<String>,
688 if_match: Option<String>,
689 if_none_match: Option<String>,
690 if_not_exists: bool,
691 user_metadata: Option<HashMap<String, String>>,
692}
693
694impl OpWrite {
695 pub fn new() -> Self {
699 Self::default()
700 }
701
702 pub fn append(&self) -> bool {
706 self.append
707 }
708
709 pub fn with_append(mut self, append: bool) -> Self {
717 self.append = append;
718 self
719 }
720
721 pub fn content_type(&self) -> Option<&str> {
723 self.content_type.as_deref()
724 }
725
726 pub fn with_content_type(mut self, content_type: &str) -> Self {
728 self.content_type = Some(content_type.to_string());
729 self
730 }
731
732 pub fn content_disposition(&self) -> Option<&str> {
734 self.content_disposition.as_deref()
735 }
736
737 pub fn with_content_disposition(mut self, content_disposition: &str) -> Self {
739 self.content_disposition = Some(content_disposition.to_string());
740 self
741 }
742
743 pub fn content_encoding(&self) -> Option<&str> {
745 self.content_encoding.as_deref()
746 }
747
748 pub fn with_content_encoding(mut self, content_encoding: &str) -> Self {
750 self.content_encoding = Some(content_encoding.to_string());
751 self
752 }
753
754 pub fn cache_control(&self) -> Option<&str> {
756 self.cache_control.as_deref()
757 }
758
759 pub fn with_cache_control(mut self, cache_control: &str) -> Self {
761 self.cache_control = Some(cache_control.to_string());
762 self
763 }
764
765 pub fn concurrent(&self) -> usize {
767 self.concurrent
768 }
769
770 pub fn with_concurrent(mut self, concurrent: usize) -> Self {
772 self.concurrent = concurrent;
773 self
774 }
775
776 pub fn with_if_match(mut self, s: &str) -> Self {
778 self.if_match = Some(s.to_string());
779 self
780 }
781
782 pub fn if_match(&self) -> Option<&str> {
784 self.if_match.as_deref()
785 }
786
787 pub fn with_if_none_match(mut self, s: &str) -> Self {
789 self.if_none_match = Some(s.to_string());
790 self
791 }
792
793 pub fn if_none_match(&self) -> Option<&str> {
795 self.if_none_match.as_deref()
796 }
797
798 pub fn with_if_not_exists(mut self, b: bool) -> Self {
800 self.if_not_exists = b;
801 self
802 }
803
804 pub fn if_not_exists(&self) -> bool {
806 self.if_not_exists
807 }
808
809 pub fn with_user_metadata(mut self, metadata: HashMap<String, String>) -> Self {
811 self.user_metadata = Some(metadata);
812 self
813 }
814
815 pub fn user_metadata(&self) -> Option<&HashMap<String, String>> {
817 self.user_metadata.as_ref()
818 }
819}
820
821#[derive(Debug, Clone, Default)]
823pub struct OpWriter {
824 chunk: Option<usize>,
825}
826
827impl OpWriter {
828 pub fn new() -> Self {
830 Self::default()
831 }
832
833 pub fn chunk(&self) -> Option<usize> {
837 self.chunk
838 }
839
840 pub fn with_chunk(mut self, chunk: usize) -> Self {
850 self.chunk = Some(chunk);
851 self
852 }
853}
854
855impl From<options::WriteOptions> for (OpWrite, OpWriter) {
856 fn from(value: options::WriteOptions) -> Self {
857 (
858 OpWrite {
859 append: value.append,
860 concurrent: value.concurrent.max(1),
862 content_type: value.content_type,
863 content_disposition: value.content_disposition,
864 content_encoding: value.content_encoding,
865 cache_control: value.cache_control,
866 if_match: value.if_match,
867 if_none_match: value.if_none_match,
868 if_not_exists: value.if_not_exists,
869 user_metadata: value.user_metadata,
870 },
871 OpWriter { chunk: value.chunk },
872 )
873 }
874}
875
876#[derive(Debug, Clone, Default)]
878pub struct OpCopy {
879 if_not_exists: bool,
880 if_match: Option<String>,
881 source_version: Option<String>,
882}
883
884impl OpCopy {
885 pub fn new() -> Self {
887 Self::default()
888 }
889
890 pub fn with_if_not_exists(mut self, if_not_exists: bool) -> Self {
895 self.if_not_exists = if_not_exists;
896 self
897 }
898
899 pub fn if_not_exists(&self) -> bool {
901 self.if_not_exists
902 }
903
904 pub fn with_if_match(mut self, if_match: impl Into<String>) -> Self {
909 self.if_match = Some(if_match.into());
910 self
911 }
912
913 pub fn if_match(&self) -> Option<&str> {
915 self.if_match.as_deref()
916 }
917
918 pub fn with_source_version(mut self, version: impl Into<String>) -> Self {
922 self.source_version = Some(version.into());
923 self
924 }
925
926 pub fn source_version(&self) -> Option<&str> {
928 self.source_version.as_deref()
929 }
930}
931
932#[derive(Debug, Clone, Default)]
934pub struct OpCopier {
935 concurrent: usize,
936 chunk: Option<usize>,
937 source_content_length_hint: Option<u64>,
938}
939
940impl OpCopier {
941 pub fn new() -> Self {
943 Self::default()
944 }
945
946 pub fn with_concurrent(mut self, concurrent: usize) -> Self {
948 self.concurrent = concurrent.max(1);
949 self
950 }
951
952 pub fn concurrent(&self) -> usize {
954 self.concurrent.max(1)
955 }
956
957 pub fn with_chunk(mut self, chunk: usize) -> Self {
959 self.chunk = Some(chunk);
960 self
961 }
962
963 pub fn chunk(&self) -> Option<usize> {
965 self.chunk
966 }
967
968 pub fn with_source_content_length_hint(mut self, content_length: u64) -> Self {
970 self.source_content_length_hint = Some(content_length);
971 self
972 }
973
974 pub fn source_content_length_hint(&self) -> Option<u64> {
976 self.source_content_length_hint
977 }
978}
979
980impl From<options::CopyOptions> for (OpCopy, OpCopier) {
981 fn from(value: options::CopyOptions) -> Self {
982 (
983 OpCopy {
984 if_not_exists: value.if_not_exists,
985 if_match: value.if_match,
986 source_version: value.source_version,
987 },
988 OpCopier {
989 concurrent: value.concurrent.max(1),
990 chunk: value.chunk,
991 source_content_length_hint: value.source_content_length_hint,
992 },
993 )
994 }
995}
996
997#[derive(Debug, Clone, Default)]
999pub struct OpRename {
1000 if_not_exists: bool,
1005}
1006
1007impl OpRename {
1008 pub fn new() -> Self {
1010 Self::default()
1011 }
1012
1013 pub fn with_if_not_exists(mut self, if_not_exists: bool) -> Self {
1024 self.if_not_exists = if_not_exists;
1025 self
1026 }
1027
1028 pub fn if_not_exists(&self) -> bool {
1030 self.if_not_exists
1031 }
1032}
1033
1034impl From<options::RenameOptions> for OpRename {
1035 fn from(value: options::RenameOptions) -> Self {
1036 Self {
1037 if_not_exists: value.if_not_exists,
1038 }
1039 }
1040}