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 CreateDir(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 DeletePath(std::string_view path);
71
72 using ReaderFuture = opendal::ffi::async::RustFutureReaderId;
73 ReaderFuture GetReader(std::string_view path);
74
75 using ListerFuture = opendal::ffi::async::RustFutureListerId;
76 ListerFuture GetLister(std::string_view path);
77
78 private:
79 rust::Box<opendal::ffi::async::Operator> operator_;
80};
81
88class Reader {
89 public:
90 // Disable copy and assign
91 Reader(const Reader &) = delete;
92 Reader &operator=(const Reader &) = delete;
93
94 // Enable move
95 Reader(Reader &&other) noexcept;
96 Reader &operator=(Reader &&other) noexcept;
97 ~Reader() noexcept;
98
99 // Constructor from ID (for tests and advanced usage)
100 explicit Reader(size_t reader_id) noexcept;
101
102 using ReadFuture = opendal::ffi::async::RustFutureRead;
103
110 ReadFuture Read(uint64_t start, uint64_t len);
111
112 private:
113 friend class Operator;
114
115 void Destroy() noexcept;
116
117 size_t reader_id_{0};
118};
119
126class Lister {
127 public:
128 // Disable copy and assign
129 Lister(const Lister &) = delete;
130 Lister &operator=(const Lister &) = delete;
131
132 // Enable move
133 Lister(Lister &&other) noexcept;
134 Lister &operator=(Lister &&other) noexcept;
135 ~Lister() noexcept;
136
137 // Constructor from ID (for tests and advanced usage)
138 explicit Lister(size_t lister_id) noexcept;
139
140 using NextFuture = opendal::ffi::async::RustFutureEntryOption;
141
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:126
Lister & operator=(Lister &&other) noexcept
Lister(Lister &&other) noexcept
opendal::ffi::async::RustFutureEntryOption NextFuture
Definition opendal_async.hpp:140
Lister & operator=(const Lister &)=delete
Lister(const Lister &)=delete
NextFuture Next()
Get the next entry in the listing.
Definition opendal_async.hpp:34
ReadFuture Read(std::string_view path)
CreateDirFuture CreateDir(std::string_view path)
opendal::ffi::async::RustFutureList ListFuture
Definition opendal_async.hpp:54
Operator(std::string_view scheme, const std::unordered_map< std::string, std::string > &config={})
opendal::ffi::async::RustFutureListerId ListerFuture
Definition opendal_async.hpp:75
ListFuture List(std::string_view path)
opendal::ffi::async::RustFutureWrite RenameFuture
Definition opendal_async.hpp:66
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
ListerFuture GetLister(std::string_view path)
opendal::ffi::async::RustFutureWrite WriteFuture
Definition opendal_async.hpp:51
opendal::ffi::async::RustFutureBool ExistsFuture
Definition opendal_async.hpp:57
RenameFuture Rename(std::string_view from, std::string_view to)
opendal::ffi::async::RustFutureReaderId ReaderFuture
Definition opendal_async.hpp:72
ReaderFuture GetReader(std::string_view path)
WriteFuture Write(std::string_view path, std::span< uint8_t > data)
DeleteFuture DeletePath(std::string_view path)
ExistsFuture Exists(std::string_view path)
opendal::ffi::async::RustFutureWrite DeleteFuture
Definition opendal_async.hpp:69
Operator & operator=(const Operator &)=delete
opendal::ffi::async::RustFutureWrite CopyFuture
Definition opendal_async.hpp:63
Operator(const Operator &)=delete
CopyFuture Copy(std::string_view from, std::string_view to)
Async Reader is designed to read data from a specific path in an asynchronous manner.
Definition opendal_async.hpp:88
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:102
Reader & operator=(const Reader &)=delete
Definition opendal_async.hpp:32
Definition data_structure.hpp:27