opendal/types/delete/
input.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 crate::Entry;
19use crate::raw::OpDelete;
20
21/// DeleteInput is the input for delete operations.
22#[non_exhaustive]
23#[derive(Default, Debug)]
24pub struct DeleteInput {
25    /// The path of the path to delete.
26    pub path: String,
27    /// The version of the path to delete.
28    pub version: Option<String>,
29    /// Whether to perform recursive deletion.
30    pub recursive: bool,
31}
32
33/// IntoDeleteInput is a helper trait that makes it easier for users to play with `Deleter`.
34pub trait IntoDeleteInput: Send + Sync + Unpin {
35    /// Convert `self` into a `DeleteInput`.
36    fn into_delete_input(self) -> DeleteInput;
37}
38
39/// Implement `IntoDeleteInput` for `DeleteInput` self.
40impl IntoDeleteInput for DeleteInput {
41    fn into_delete_input(self) -> DeleteInput {
42        self
43    }
44}
45
46/// Implement `IntoDeleteInput` for `&str` so we can use `&str` as a DeleteInput.
47impl IntoDeleteInput for &str {
48    fn into_delete_input(self) -> DeleteInput {
49        DeleteInput {
50            path: self.to_string(),
51            recursive: false,
52            ..Default::default()
53        }
54    }
55}
56
57/// Implement `IntoDeleteInput` for `String` so we can use `Vec<String>` as a DeleteInput stream.
58impl IntoDeleteInput for String {
59    fn into_delete_input(self) -> DeleteInput {
60        DeleteInput {
61            path: self,
62            recursive: false,
63            ..Default::default()
64        }
65    }
66}
67
68/// Implement `IntoDeleteInput` for `(String, OpDelete)` so we can use `(String, OpDelete)`
69/// as a DeleteInput stream.
70impl IntoDeleteInput for (String, OpDelete) {
71    fn into_delete_input(self) -> DeleteInput {
72        let (path, args) = self;
73
74        let mut input = DeleteInput {
75            path,
76            recursive: args.recursive(),
77            ..Default::default()
78        };
79
80        if let Some(version) = args.version() {
81            input.version = Some(version.to_string());
82        }
83        input
84    }
85}
86
87/// Implement `IntoDeleteInput` for `Entry` so we can use `Lister` as a DeleteInput stream.
88impl IntoDeleteInput for Entry {
89    fn into_delete_input(self) -> DeleteInput {
90        let (path, meta) = self.into_parts();
91
92        let mut input = DeleteInput {
93            path,
94            recursive: false,
95            ..Default::default()
96        };
97
98        if let Some(version) = meta.version() {
99            input.version = Some(version.to_string());
100        }
101        input
102    }
103}