Apache OpenDALâ„¢ C++ Binding
The C++ binding for Apache OpenDALâ„¢
Loading...
Searching...
No Matches
opendal_async.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <cstdint>
23#include <optional>
24#include <span>
25#include <string>
26#include <string_view>
27#include <unordered_map>
28
29#include "async.rs.h"
30#include "async_defs.hpp"
31
32namespace opendal::async {
33
34class Operator {
35 public:
36 Operator(std::string_view scheme,
37 const std::unordered_map<std::string, std::string> &config = {});
38
39 // Disable copy and assign
40 Operator(const Operator &) = delete;
41 Operator &operator=(const Operator &) = delete;
42
43 // Enable move
44 Operator(Operator &&) = default;
45 Operator &operator=(Operator &&) = default;
46 ~Operator() = default;
47
48 using ReadFuture = opendal::ffi::async::RustFutureRead;
49 ReadFuture read(std::string_view path);
50
51 using WriteFuture = opendal::ffi::async::RustFutureWrite;
52 WriteFuture write(std::string_view path, std::span<uint8_t> data);
53
54 using ListFuture = opendal::ffi::async::RustFutureList;
55 ListFuture list(std::string_view path);
56
57 using ExistsFuture = opendal::ffi::async::RustFutureBool;
58 ExistsFuture exists(std::string_view path);
59
60 using CreateDirFuture = opendal::ffi::async::RustFutureWrite;
61 CreateDirFuture create_dir(std::string_view path);
62
63 using CopyFuture = opendal::ffi::async::RustFutureWrite;
64 CopyFuture copy(std::string_view from, std::string_view to);
65
66 using RenameFuture = opendal::ffi::async::RustFutureWrite;
67 RenameFuture rename(std::string_view from, std::string_view to);
68
69 using DeleteFuture = opendal::ffi::async::RustFutureWrite;
70 DeleteFuture delete_path(std::string_view path);
71
72 using RemoveAllFuture = opendal::ffi::async::RustFutureWrite;
73 RemoveAllFuture remove_all(std::string_view path);
74
75 using ReaderFuture = opendal::ffi::async::RustFutureReaderId;
76 ReaderFuture reader(std::string_view path);
77
78 using ListerFuture = opendal::ffi::async::RustFutureListerId;
79 ListerFuture lister(std::string_view path);
80
81 private:
82 rust::Box<opendal::ffi::async::Operator> operator_;
83};
84
90class Reader {
91 public:
92 // Disable copy and assign
93 Reader(const Reader &) = delete;
94 Reader &operator=(const Reader &) = delete;
95
96 // Enable move
97 Reader(Reader &&other) noexcept;
98 Reader &operator=(Reader &&other) noexcept;
99 ~Reader() noexcept;
100
101 // Constructor from ID (for tests and advanced usage)
102 explicit Reader(size_t reader_id) noexcept;
103
104 using ReadFuture = opendal::ffi::async::RustFutureRead;
105
112 ReadFuture read(uint64_t start, uint64_t len);
113
114 private:
115 friend class Operator;
116
117 void destroy() noexcept;
118
119 size_t reader_id_{0};
120};
121
127class Lister {
128 public:
129 // Disable copy and assign
130 Lister(const Lister &) = delete;
131 Lister &operator=(const Lister &) = delete;
132
133 // Enable move
134 Lister(Lister &&other) noexcept;
135 Lister &operator=(Lister &&other) noexcept;
136 ~Lister() noexcept;
137
138 // Constructor from ID (for tests and advanced usage)
139 explicit Lister(size_t lister_id) noexcept;
140
141 using NextFuture = opendal::ffi::async::RustFutureEntryOption;
142
148
149 private:
150 friend class Operator;
151
152 void destroy() noexcept;
153
154 size_t lister_id_{0};
155};
156
157} // namespace opendal::async
Async Lister is designed to list entries at a specified path in an asynchronous manner.
Definition opendal_async.hpp:127
Lister & operator=(Lister &&other) noexcept
Lister(Lister &&other) noexcept
NextFuture next()
Get the next entry in the listing.
opendal::ffi::async::RustFutureEntryOption NextFuture
Definition opendal_async.hpp:141
Lister & operator=(const Lister &)=delete
Lister(const Lister &)=delete
Definition opendal_async.hpp:34
opendal::ffi::async::RustFutureList ListFuture
Definition opendal_async.hpp:54
RemoveAllFuture remove_all(std::string_view path)
Operator(std::string_view scheme, const std::unordered_map< std::string, std::string > &config={})
opendal::ffi::async::RustFutureListerId ListerFuture
Definition opendal_async.hpp:78
CopyFuture copy(std::string_view from, std::string_view to)
ListerFuture lister(std::string_view path)
opendal::ffi::async::RustFutureWrite RemoveAllFuture
Definition opendal_async.hpp:72
RenameFuture rename(std::string_view from, std::string_view to)
opendal::ffi::async::RustFutureWrite RenameFuture
Definition opendal_async.hpp:66
ReadFuture read(std::string_view path)
WriteFuture write(std::string_view path, std::span< uint8_t > data)
opendal::ffi::async::RustFutureRead ReadFuture
Definition opendal_async.hpp:48
opendal::ffi::async::RustFutureWrite CreateDirFuture
Definition opendal_async.hpp:60
Operator & operator=(Operator &&)=default
Operator(Operator &&)=default
DeleteFuture delete_path(std::string_view path)
opendal::ffi::async::RustFutureWrite WriteFuture
Definition opendal_async.hpp:51
opendal::ffi::async::RustFutureBool ExistsFuture
Definition opendal_async.hpp:57
opendal::ffi::async::RustFutureReaderId ReaderFuture
Definition opendal_async.hpp:75
ListFuture list(std::string_view path)
CreateDirFuture create_dir(std::string_view path)
opendal::ffi::async::RustFutureWrite DeleteFuture
Definition opendal_async.hpp:69
ReaderFuture reader(std::string_view path)
Operator & operator=(const Operator &)=delete
ExistsFuture exists(std::string_view path)
opendal::ffi::async::RustFutureWrite CopyFuture
Definition opendal_async.hpp:63
Operator(const Operator &)=delete
Async Reader is designed to read data from a specific path in an asynchronous manner.
Definition opendal_async.hpp:90
Reader(const Reader &)=delete
Reader & operator=(Reader &&other) noexcept
ReadFuture read(uint64_t start, uint64_t len)
Read data from the specified range.
Reader(Reader &&other) noexcept
opendal::ffi::async::RustFutureRead ReadFuture
Definition opendal_async.hpp:104
Reader & operator=(const Reader &)=delete
Definition opendal_async.hpp:32
Definition data_structure.hpp:28