opendal_core/raw/operation.rs
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use std::fmt::Display;
19use std::fmt::Formatter;
20
21/// Identifies the operation being performed.
22///
23/// Most variants map to methods on the `Access` trait, although some names
24/// differ to improve readability.
25///
26/// An operation might have different meanings and costs depending on a
27/// storage service.
28#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Default)]
29#[non_exhaustive]
30pub enum Operation {
31 /// Operation to retrieve information about the specified storage services.
32 #[default]
33 Info,
34 /// Operation to create a directory.
35 CreateDir,
36 /// Operation to read a file.
37 Read,
38 /// Operation to write to a file.
39 Write,
40 /// Operation to copy a file.
41 Copy,
42 /// Operation to compose multiple files into one file.
43 Compose,
44 /// Operation to rename a file.
45 Rename,
46 /// Operation to restore a file.
47 Restore,
48 /// Operation to stat a file or a directory.
49 Stat,
50 /// Operation to delete files.
51 Delete,
52 /// Operation to get the next file from the list.
53 List,
54 /// Operation to generate a presigned URL.
55 Presign,
56}
57
58impl Operation {
59 /// Convert self into static str.
60 pub fn into_static(self) -> &'static str {
61 self.into()
62 }
63}
64
65impl Display for Operation {
66 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
67 write!(f, "{}", self.into_static())
68 }
69}
70
71impl From<Operation> for &'static str {
72 fn from(v: Operation) -> &'static str {
73 match v {
74 Operation::Info => "info",
75 Operation::CreateDir => "create_dir",
76 Operation::Read => "read",
77 Operation::Write => "write",
78 Operation::Copy => "copy",
79 Operation::Compose => "compose",
80 Operation::Rename => "rename",
81 Operation::Restore => "restore",
82 Operation::Stat => "stat",
83 Operation::Delete => "delete",
84 Operation::List => "list",
85 Operation::Presign => "presign",
86 }
87 }
88}
89
90impl From<Operation> for String {
91 fn from(v: Operation) -> Self {
92 v.into_static().to_string()
93 }
94}
95
96/// A service-specific operation name attached to HTTP requests.
97///
98/// While [`Operation`] describes the OpenDAL-level operation (e.g., read, write, list),
99/// `ServiceOperation` describes the specific backend API call being made as a supplement.
100///
101/// Services attach this as an HTTP request extension so that observability layers
102/// can provide finer-grained breakdowns of HTTP traffic.
103#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
104pub struct ServiceOperation(pub &'static str);