1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use std::fmt::Debug;
/// Capability defines the supported operations and their constraints for a storage Operator.
///
/// # Overview
///
/// This structure provides a comprehensive description of an Operator's capabilities,
/// including:
///
/// - Basic operations support (read, write, delete, etc.)
/// - Advanced operation variants (conditional operations, metadata handling)
/// - Operational constraints (size limits, batch limitations)
///
/// # Capability Types
///
/// Every operator maintains two capability sets:
///
/// 1. [`OperatorInfo::native_capability`][crate::OperatorInfo::native_capability]:
/// Represents operations natively supported by the storage backend.
///
/// 2. [`OperatorInfo::full_capability`][crate::OperatorInfo::full_capability]:
/// Represents all available operations, including those implemented through
/// alternative mechanisms.
///
/// # Implementation Details
///
/// Some operations might be available even when not natively supported by the
/// backend. For example:
///
/// - Blocking operations are provided through the BlockingLayer
///
/// Developers should:
/// - Use `full_capability` to determine available operations
/// - Use `native_capability` to identify optimized operations
///
/// # Field Naming Conventions
///
/// Fields follow these naming patterns:
///
/// - Basic operations: Simple lowercase (e.g., `read`, `write`)
/// - Compound operations: Underscore-separated (e.g., `presign_read`)
/// - Variants: Capability description (e.g., `write_can_empty`)
/// - Parameterized operations: With-style (e.g., `read_with_if_match`)
/// - Limitations: Constraint description (e.g., `write_multi_max_size`)
/// - Metadata Results: Returning metadata capabilities (e.g., `stat_has_content_length`)
///
/// All capability fields are public and can be accessed directly.
#[derive(Copy, Clone, Default)]
pub struct Capability {
/// Indicates if the operator supports metadata retrieval operations.
pub stat: bool,
/// Indicates if conditional stat operations using If-Match are supported.
pub stat_with_if_match: bool,
/// Indicates if conditional stat operations using If-None-Match are supported.
pub stat_with_if_none_match: bool,
/// Indicates if Cache-Control header override is supported during stat operations.
pub stat_with_override_cache_control: bool,
/// Indicates if Content-Disposition header override is supported during stat operations.
pub stat_with_override_content_disposition: bool,
/// Indicates if Content-Type header override is supported during stat operations.
pub stat_with_override_content_type: bool,
/// Indicates if versions stat operations are supported.
pub stat_with_version: bool,
/// Indicates whether cache control information is available in stat response
pub stat_has_cache_control: bool,
/// Indicates whether content disposition information is available in stat response
pub stat_has_content_disposition: bool,
/// Indicates whether content length information is available in stat response
pub stat_has_content_length: bool,
/// Indicates whether content MD5 checksum is available in stat response
pub stat_has_content_md5: bool,
/// Indicates whether content range information is available in stat response
pub stat_has_content_range: bool,
/// Indicates whether content type information is available in stat response
pub stat_has_content_type: bool,
/// Indicates whether content encoding information is available in stat response
pub stat_has_content_encoding: bool,
/// Indicates whether entity tag is available in stat response
pub stat_has_etag: bool,
/// Indicates whether last modified timestamp is available in stat response
pub stat_has_last_modified: bool,
/// Indicates whether version information is available in stat response
pub stat_has_version: bool,
/// Indicates whether user-defined metadata is available in stat response
pub stat_has_user_metadata: bool,
/// Indicates if the operator supports read operations.
pub read: bool,
/// Indicates if conditional read operations using If-Match are supported.
pub read_with_if_match: bool,
/// Indicates if conditional read operations using If-None-Match are supported.
pub read_with_if_none_match: bool,
/// Indicates if Cache-Control header override is supported during read operations.
pub read_with_override_cache_control: bool,
/// Indicates if Content-Disposition header override is supported during read operations.
pub read_with_override_content_disposition: bool,
/// Indicates if Content-Type header override is supported during read operations.
pub read_with_override_content_type: bool,
/// Indicates if versions read operations are supported.
pub read_with_version: bool,
/// Indicates if the operator supports write operations.
pub write: bool,
/// Indicates if multiple write operations can be performed on the same object.
pub write_can_multi: bool,
/// Indicates if writing empty content is supported.
pub write_can_empty: bool,
/// Indicates if append operations are supported.
pub write_can_append: bool,
/// Indicates if Content-Type can be specified during write operations.
pub write_with_content_type: bool,
/// Indicates if Content-Disposition can be specified during write operations.
pub write_with_content_disposition: bool,
/// Indicates if Content-Encoding can be specified during write operations.
pub write_with_content_encoding: bool,
/// Indicates if Cache-Control can be specified during write operations.
pub write_with_cache_control: bool,
/// Indicates if conditional write operations using If-Match are supported.
pub write_with_if_match: bool,
/// Indicates if conditional write operations using If-None-Match are supported.
pub write_with_if_none_match: bool,
/// Indicates if write operations can be conditional on object non-existence.
pub write_with_if_not_exists: bool,
/// Indicates if custom user metadata can be attached during write operations.
pub write_with_user_metadata: bool,
/// Maximum size supported for multipart uploads.
/// For example, AWS S3 supports up to 5GiB per part in multipart uploads.
pub write_multi_max_size: Option<usize>,
/// Minimum size required for multipart uploads (except for the last part).
/// For example, AWS S3 requires at least 5MiB per part.
pub write_multi_min_size: Option<usize>,
/// Maximum total size supported for write operations.
/// For example, Cloudflare D1 has a 1MB total size limit.
pub write_total_max_size: Option<usize>,
/// Indicates if directory creation is supported.
pub create_dir: bool,
/// Indicates if delete operations are supported.
pub delete: bool,
/// Indicates if versions delete operations are supported.
pub delete_with_version: bool,
/// Maximum size supported for single delete operations.
pub delete_max_size: Option<usize>,
/// Indicates if copy operations are supported.
pub copy: bool,
/// Indicates if rename operations are supported.
pub rename: bool,
/// Indicates if list operations are supported.
pub list: bool,
/// Indicates if list operations support result limiting.
pub list_with_limit: bool,
/// Indicates if list operations support continuation from a specific point.
pub list_with_start_after: bool,
/// Indicates if recursive listing is supported.
pub list_with_recursive: bool,
/// Indicates if versions listing is supported.
#[deprecated(since = "0.51.1", note = "use with_versions instead")]
pub list_with_version: bool,
/// Indicates if listing with versions included is supported.
pub list_with_versions: bool,
/// Indicates if listing with deleted files included is supported.
pub list_with_deleted: bool,
/// Indicates whether cache control information is available in list response
pub list_has_cache_control: bool,
/// Indicates whether content disposition information is available in list response
pub list_has_content_disposition: bool,
/// Indicates whether content length information is available in list response
pub list_has_content_length: bool,
/// Indicates whether content MD5 checksum is available in list response
pub list_has_content_md5: bool,
/// Indicates whether content range information is available in list response
pub list_has_content_range: bool,
/// Indicates whether content type information is available in list response
pub list_has_content_type: bool,
/// Indicates whether entity tag is available in list response
pub list_has_etag: bool,
/// Indicates whether last modified timestamp is available in list response
pub list_has_last_modified: bool,
/// Indicates whether version information is available in list response
pub list_has_version: bool,
/// Indicates whether user-defined metadata is available in list response
pub list_has_user_metadata: bool,
/// Indicates if presigned URL generation is supported.
pub presign: bool,
/// Indicates if presigned URLs for read operations are supported.
pub presign_read: bool,
/// Indicates if presigned URLs for stat operations are supported.
pub presign_stat: bool,
/// Indicates if presigned URLs for write operations are supported.
pub presign_write: bool,
/// Indicate if the operator supports shared access.
pub shared: bool,
/// Indicates if blocking operations are supported.
pub blocking: bool,
}
impl Debug for Capability {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// NOTE: All services in opendal are readable.
if self.read {
f.write_str("Read")?;
}
if self.write {
f.write_str("| Write")?;
}
if self.list {
f.write_str("| List")?;
}
if self.presign {
f.write_str("| Presign")?;
}
if self.shared {
f.write_str("| Shared")?;
}
if self.blocking {
f.write_str("| Blocking")?;
}
Ok(())
}
}