Skip to main content

s3_wire/operation/multipart/
listing.rs

1use super::{PartNumber, UploadId};
2use crate::operation::{Checksum, ChecksumType, ObjectKey, PageSize, RequestIds};
3
4/// Request for one page of in-progress multipart uploads.
5#[derive(Clone, Debug, Default, Eq, PartialEq)]
6pub struct ListMultipartUploadsRequest {
7    /// Only uploads with keys beginning with this prefix are returned.
8    pub prefix: Option<String>,
9    /// Groups upload keys using this delimiter.
10    pub delimiter: Option<String>,
11    /// Key marker from a preceding response.
12    pub key_marker: Option<String>,
13    /// Upload-ID marker from a preceding response.
14    pub upload_id_marker: Option<UploadId>,
15    /// Maximum uploads requested from the service.
16    pub max_uploads: PageSize,
17}
18
19/// One in-progress multipart upload returned by the service.
20#[derive(Clone, Debug, Eq, PartialEq)]
21pub struct MultipartUploadEntry {
22    /// Destination object key.
23    pub key: ObjectKey,
24    /// Opaque upload identifier.
25    upload_id: UploadId,
26    /// Initiation time.
27    pub initiated: Option<time::OffsetDateTime>,
28    /// Storage class, when supplied.
29    pub storage_class: Option<String>,
30}
31
32impl MultipartUploadEntry {
33    pub(crate) fn new(
34        key: ObjectKey,
35        upload_id: UploadId,
36        initiated: Option<time::OffsetDateTime>,
37        storage_class: Option<String>,
38    ) -> Self {
39        Self {
40            key,
41            upload_id,
42            initiated,
43            storage_class,
44        }
45    }
46
47    /// Returns the validated upload identifier.
48    pub const fn upload_id(&self) -> &UploadId {
49        &self.upload_id
50    }
51}
52
53/// One page of in-progress multipart uploads.
54#[derive(Clone, Debug, Default, Eq, PartialEq)]
55pub struct ListMultipartUploadsOutput {
56    /// Upload entries.
57    pub uploads: Vec<MultipartUploadEntry>,
58    /// Grouped key prefixes.
59    pub common_prefixes: Vec<String>,
60    /// Whether another page exists.
61    pub is_truncated: bool,
62    /// Key marker for the next page.
63    pub next_key_marker: Option<String>,
64    /// Upload-ID marker for the next page.
65    pub next_upload_id_marker: Option<UploadId>,
66    /// Service request identifiers.
67    pub request_ids: RequestIds,
68}
69
70/// Request for one page of parts belonging to an in-progress upload.
71#[derive(Clone, Debug, Eq, PartialEq)]
72pub struct ListPartsRequest {
73    key: ObjectKey,
74    upload_id: UploadId,
75    /// Lists only parts after this part number.
76    pub part_number_marker: Option<PartNumber>,
77    /// Maximum parts requested from the service.
78    pub max_parts: PageSize,
79}
80
81impl ListPartsRequest {
82    /// Constructs a request for the first page of an upload's parts.
83    pub fn new(key: ObjectKey, upload_id: UploadId) -> Self {
84        Self {
85            key,
86            upload_id,
87            part_number_marker: None,
88            max_parts: PageSize::default(),
89        }
90    }
91
92    /// Returns the destination object key.
93    pub const fn key(&self) -> &ObjectKey {
94        &self.key
95    }
96
97    /// Returns the service-issued upload identifier.
98    pub const fn upload_id(&self) -> &UploadId {
99        &self.upload_id
100    }
101}
102
103/// One uploaded part returned by `ListParts`.
104#[derive(Clone, Debug, Eq, PartialEq)]
105pub struct ListedPart {
106    part_number: PartNumber,
107    /// Entity tag used when completing the upload.
108    pub e_tag: String,
109    /// Time at which S3 accepted the part.
110    pub last_modified: Option<time::OffsetDateTime>,
111    /// Part size in bytes.
112    pub size: u64,
113    /// Checksums recorded for this part.
114    pub checksum: Checksum,
115}
116
117impl ListedPart {
118    pub(crate) fn new(
119        part_number: PartNumber,
120        e_tag: String,
121        last_modified: Option<time::OffsetDateTime>,
122        size: u64,
123        checksum: Checksum,
124    ) -> Self {
125        Self {
126            part_number,
127            e_tag,
128            last_modified,
129            size,
130            checksum,
131        }
132    }
133
134    /// Returns the validated part number.
135    pub const fn part_number(&self) -> PartNumber {
136        self.part_number
137    }
138
139    /// Converts this service entry into a completion descriptor.
140    pub fn completed_part(&self) -> Result<super::CompletedPart, super::MultipartError> {
141        super::CompletedPart::new(self.part_number.get(), self.e_tag.clone())
142            .map(|part| part.with_checksum(self.checksum.clone()))
143    }
144}
145
146/// One bounded page returned by `ListParts`.
147#[derive(Clone, Debug, Default, Eq, PartialEq)]
148pub struct ListPartsOutput {
149    /// Parts in ascending part-number order.
150    pub parts: Vec<ListedPart>,
151    /// Whether another page exists.
152    pub is_truncated: bool,
153    /// Marker to use for the next page.
154    pub next_part_number_marker: Option<PartNumber>,
155    /// Checksum algorithm selected when the upload was created.
156    pub checksum_algorithm: Option<String>,
157    /// Object-level checksum aggregation selected for the upload.
158    pub checksum_type: Option<ChecksumType>,
159    /// Service request identifiers.
160    pub request_ids: RequestIds,
161}