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
31namespace opendal::async {
32
33class Operator {
34 public:
35 Operator(std::string_view scheme,
36 const std::unordered_map<std::string, std::string> &config = {});
37
38 // Disable copy and assign
39 Operator(const Operator &) = delete;
40 Operator &operator=(const Operator &) = delete;
41
42 // Enable move
43 Operator(Operator &&) = default;
44 Operator &operator=(Operator &&) = default;
45 ~Operator() = default;
46
47 using ReadFuture = opendal::ffi::async_op::RustFutureRead;
48 ReadFuture Read(std::string_view path);
49
50 using WriteFuture = opendal::ffi::async_op::RustFutureWrite;
51 WriteFuture Write(std::string_view path, std::span<uint8_t> data);
52
53 using ListFuture = opendal::ffi::async_op::RustFutureList;
54 ListFuture List(std::string_view path);
55
56 using ExistsFuture = opendal::ffi::async_op::RustFutureBool;
57 ExistsFuture Exists(std::string_view path);
58
59 using CreateDirFuture = opendal::ffi::async_op::RustFutureWrite;
60 CreateDirFuture CreateDir(std::string_view path);
61
62 using CopyFuture = opendal::ffi::async_op::RustFutureWrite;
63 CopyFuture Copy(std::string_view from, std::string_view to);
64
65 using RenameFuture = opendal::ffi::async_op::RustFutureWrite;
66 RenameFuture Rename(std::string_view from, std::string_view to);
67
68 using DeleteFuture = opendal::ffi::async_op::RustFutureWrite;
69 DeleteFuture DeletePath(std::string_view path);
70
71 using ReaderFuture = opendal::ffi::async_op::RustFutureReaderId;
72 ReaderFuture GetReader(std::string_view path);
73
74 using ListerFuture = opendal::ffi::async_op::RustFutureListerId;
75 ListerFuture GetLister(std::string_view path);
76
77 private:
78 rust::Box<opendal::ffi::async_op::Operator> operator_;
79};
80
87class Reader {
88 public:
89 // Disable copy and assign
90 Reader(const Reader &) = delete;
91 Reader &operator=(const Reader &) = delete;
92
93 // Enable move
94 Reader(Reader &&other) noexcept;
95 Reader &operator=(Reader &&other) noexcept;
96 ~Reader() noexcept;
97
98 // Constructor from ID (for tests and advanced usage)
99 explicit Reader(size_t reader_id) noexcept;
100
101 using ReadFuture = opendal::ffi::async_op::RustFutureRead;
102
109 ReadFuture Read(uint64_t start, uint64_t len);
110
111 private:
112 friend class Operator;
113
114 void Destroy() noexcept;
115
116 size_t reader_id_{0};
117};
118
125class Lister {
126 public:
127 // Disable copy and assign
128 Lister(const Lister &) = delete;
129 Lister &operator=(const Lister &) = delete;
130
131 // Enable move
132 Lister(Lister &&other) noexcept;
133 Lister &operator=(Lister &&other) noexcept;
134 ~Lister() noexcept;
135
136 // Constructor from ID (for tests and advanced usage)
137 explicit Lister(size_t lister_id) noexcept;
138
139 using NextFuture = opendal::ffi::async_op::RustFutureEntryOption;
140
147
148 private:
149 friend class Operator;
150
151 void Destroy() noexcept;
152
153 size_t lister_id_{0};
154};
155
156} // namespace opendal::async
Async Lister is designed to list entries at a specified path in an asynchronous manner.
Definition opendal_async.hpp:125
opendal::ffi::async_op::RustFutureEntryOption NextFuture
Definition opendal_async.hpp:139
Lister & operator=(Lister &&other) noexcept
Lister(Lister &&other) noexcept
Lister & operator=(const Lister &)=delete
Lister(const Lister &)=delete
NextFuture Next()
Get the next entry in the listing.
Definition opendal_async.hpp:33
ReadFuture Read(std::string_view path)
opendal::ffi::async_op::RustFutureWrite DeleteFuture
Definition opendal_async.hpp:68
CreateDirFuture CreateDir(std::string_view path)
Operator(std::string_view scheme, const std::unordered_map< std::string, std::string > &config={})
opendal::ffi::async_op::RustFutureWrite CopyFuture
Definition opendal_async.hpp:62
opendal::ffi::async_op::RustFutureReaderId ReaderFuture
Definition opendal_async.hpp:71
ListFuture List(std::string_view path)
opendal::ffi::async_op::RustFutureBool ExistsFuture
Definition opendal_async.hpp:56
opendal::ffi::async_op::RustFutureListerId ListerFuture
Definition opendal_async.hpp:74
Operator & operator=(Operator &&)=default
Operator(Operator &&)=default
ListerFuture GetLister(std::string_view path)
RenameFuture Rename(std::string_view from, std::string_view to)
ReaderFuture GetReader(std::string_view path)
WriteFuture Write(std::string_view path, std::span< uint8_t > data)
opendal::ffi::async_op::RustFutureList ListFuture
Definition opendal_async.hpp:53
opendal::ffi::async_op::RustFutureWrite RenameFuture
Definition opendal_async.hpp:65
DeleteFuture DeletePath(std::string_view path)
ExistsFuture Exists(std::string_view path)
opendal::ffi::async_op::RustFutureWrite CreateDirFuture
Definition opendal_async.hpp:59
Operator & operator=(const Operator &)=delete
opendal::ffi::async_op::RustFutureWrite WriteFuture
Definition opendal_async.hpp:50
Operator(const Operator &)=delete
opendal::ffi::async_op::RustFutureRead ReadFuture
Definition opendal_async.hpp:47
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:87
Reader(const Reader &)=delete
Reader & operator=(Reader &&other) noexcept
opendal::ffi::async_op::RustFutureRead ReadFuture
Definition opendal_async.hpp:101
ReadFuture Read(uint64_t start, uint64_t len)
Read data from the specified range.
Reader(Reader &&other) noexcept
Reader & operator=(const Reader &)=delete
Definition opendal_async.hpp:31
Definition data_structure.hpp:27