Skip to content

Commit 53143d4

Browse files
use macro
1 parent 70400e0 commit 53143d4

File tree

4 files changed

+329
-707
lines changed

4 files changed

+329
-707
lines changed

bindings/c/cbindgen.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ no_includes = true
4646
sys_includes = ["stdint.h", "stddef.h", "stdbool.h"]
4747

4848
[parse]
49-
include = ["opendal"]
49+
include = ["opendal_c"]
5050
parse_deps = true
5151

5252
[fn]

bindings/c/include/opendal.h

Lines changed: 9 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -109,126 +109,6 @@ typedef enum opendal_future_status {
109109
OPENDAL_FUTURE_CANCELED = 3,
110110
} opendal_future_status;
111111

112-
/**
113-
* The `Operator` serves as the entry point for all public asynchronous APIs.
114-
*
115-
* For more details about the `Operator`, refer to the [`concepts`][crate::docs::concepts] section.
116-
*
117-
* All cloned `Operator` instances share the same internal state, such as
118-
* `HttpClient` and `Runtime`. Some layers may modify the internal state of
119-
* the `Operator` too like inject logging and metrics for `HttpClient`.
120-
*
121-
* ## Build
122-
*
123-
* Users can initialize an `Operator` through the following methods:
124-
*
125-
* - [`Operator::new`]: Creates an operator using a [`services`] builder, such as [`services::S3`].
126-
* - [`Operator::from_config`]: Creates an operator using a [`services`] configuration, such as [`services::S3Config`].
127-
* - [`Operator::from_iter`]: Creates an operator from an iterator of configuration key-value pairs.
128-
*
129-
* ```
130-
* # use anyhow::Result;
131-
* use opendal::services::Memory;
132-
* use opendal::Operator;
133-
* async fn test() -> Result<()> {
134-
* // Build an `Operator` to start operating the storage.
135-
* let _: Operator = Operator::new(Memory::default())?.finish();
136-
*
137-
* Ok(())
138-
* }
139-
* ```
140-
*
141-
* ## Layer
142-
*
143-
* After the operator is built, users can add the layers they need on top of it.
144-
*
145-
* OpenDAL offers various layers for users to choose from, such as `RetryLayer`, `LoggingLayer`, and more. Visit [`layers`] for further details.
146-
*
147-
* Please note that `Layer` can modify internal contexts such as `HttpClient`
148-
* and `Runtime` for all clones of given operator. Therefore, it is recommended
149-
* to add layers before interacting with the storage. Adding or duplicating
150-
* layers after accessing the storage may result in unexpected behavior.
151-
*
152-
* ```
153-
* # use anyhow::Result;
154-
* use opendal::layers::RetryLayer;
155-
* use opendal::services::Memory;
156-
* use opendal::Operator;
157-
* async fn test() -> Result<()> {
158-
* let op: Operator = Operator::new(Memory::default())?.finish();
159-
*
160-
* // OpenDAL will retry failed operations now.
161-
* let op = op.layer(RetryLayer::default());
162-
*
163-
* Ok(())
164-
* }
165-
* ```
166-
*
167-
* ## Operate
168-
*
169-
* After the operator is built and the layers are added, users can start operating the storage.
170-
*
171-
* The operator is `Send`, `Sync`, and `Clone`. It has no internal state, and all APIs only take
172-
* a `&self` reference, making it safe to share the operator across threads.
173-
*
174-
* Operator provides a consistent API pattern for data operations. For reading operations, it exposes:
175-
*
176-
* - [`Operator::read`]: Executes a read operation.
177-
* - [`Operator::read_with`]: Executes a read operation with additional options using the builder pattern.
178-
* - [`Operator::read_options`]: Executes a read operation with extra options provided via a [`options::ReadOptions`] struct.
179-
* - [`Operator::reader`]: Creates a reader for streaming data, allowing for flexible access.
180-
* - [`Operator::reader_with`]: Creates a reader with advanced options using the builder pattern.
181-
* - [`Operator::reader_options`]: Creates a reader with extra options provided via a [`options::ReadOptions`] struct.
182-
*
183-
* The [`Reader`] created by [`Operator`] supports custom read control methods and can be converted
184-
* into [`futures::AsyncRead`] or [`futures::Stream`] for broader ecosystem compatibility.
185-
*
186-
* ```no_run
187-
* use opendal::layers::LoggingLayer;
188-
* use opendal::options;
189-
* use opendal::services;
190-
* use opendal::Operator;
191-
* use opendal::Result;
192-
*
193-
* #[tokio::main]
194-
* async fn main() -> Result<()> {
195-
* // Pick a builder and configure it.
196-
* let mut builder = services::S3::default().bucket("test");
197-
*
198-
* // Init an operator
199-
* let op = Operator::new(builder)?
200-
* // Init with logging layer enabled.
201-
* .layer(LoggingLayer::default())
202-
* .finish();
203-
*
204-
* // Fetch this file's metadata
205-
* let meta = op.stat("hello.txt").await?;
206-
* let length = meta.content_length();
207-
*
208-
* // Read data from `hello.txt` with options.
209-
* let bs = op
210-
* .read_with("hello.txt")
211-
* .range(0..8 * 1024 * 1024)
212-
* .chunk(1024 * 1024)
213-
* .concurrent(4)
214-
* .await?;
215-
*
216-
* // The same to:
217-
* let bs = op
218-
* .read_options("hello.txt", options::ReadOptions {
219-
* range: (0..8 * 1024 * 1024).into(),
220-
* chunk: Some(1024 * 1024),
221-
* concurrent: 4,
222-
* ..Default::default()
223-
* })
224-
* .await?;
225-
*
226-
* Ok(())
227-
* }
228-
* ```
229-
*/
230-
typedef struct Operator Operator;
231-
232112
typedef struct Option_JoinHandle Option_JoinHandle;
233113

234114
typedef struct Option_Receiver_Result Option_Receiver_Result;
@@ -584,7 +464,7 @@ typedef struct opendal_async_operator {
584464
/**
585465
* Internal pointer to the Rust async Operator.
586466
*/
587-
struct Operator *inner;
467+
Operator *inner;
588468
} opendal_async_operator;
589469

590470
/**
@@ -892,6 +772,14 @@ typedef struct opendal_result_writer_write {
892772
extern "C" {
893773
#endif // __cplusplus
894774

775+
extern const enum opendal_future_status OPENDAL_FUTURE_PENDING;
776+
777+
extern const enum opendal_future_status OPENDAL_FUTURE_READY;
778+
779+
extern const enum opendal_future_status OPENDAL_FUTURE_ERROR;
780+
781+
extern const enum opendal_future_status OPENDAL_FUTURE_CANCELED;
782+
895783
/**
896784
* \brief Frees the opendal_error, ok to call on NULL
897785
*/
@@ -1621,25 +1509,8 @@ void opendal_async_operator_free(const struct opendal_async_operator *op);
16211509
struct opendal_result_future_stat opendal_async_operator_stat(const struct opendal_async_operator *op,
16221510
const char *path);
16231511

1624-
/**
1625-
* \brief Await an asynchronous stat future and return the resulting metadata.
1626-
*
1627-
* This function consumes the provided future pointer. After calling this function,
1628-
* the future pointer must not be reused.
1629-
*/
16301512
struct opendal_result_stat opendal_future_stat_await(struct opendal_future_stat *future);
16311513

1632-
/**
1633-
* \brief Non-blocking check whether a stat future has completed and, if so, fill output.
1634-
*/
1635-
enum opendal_future_status opendal_future_stat_poll(struct opendal_future_stat *future,
1636-
struct opendal_result_stat *out);
1637-
1638-
/**
1639-
* \brief Non-blocking check whether the stat future has completed.
1640-
*/
1641-
bool opendal_future_stat_is_ready(const struct opendal_future_stat *future);
1642-
16431514
/**
16441515
* \brief Cancel and free a stat future without awaiting it.
16451516
*/
@@ -1654,22 +1525,8 @@ void opendal_future_stat_free(struct opendal_future_stat *future);
16541525
struct opendal_result_future_read opendal_async_operator_read(const struct opendal_async_operator *op,
16551526
const char *path);
16561527

1657-
/**
1658-
* \brief Await an asynchronous read future and return the resulting data.
1659-
*/
16601528
struct opendal_result_read opendal_future_read_await(struct opendal_future_read *future);
16611529

1662-
/**
1663-
* \brief Non-blocking check whether a read future has completed and, if so, fill output.
1664-
*/
1665-
enum opendal_future_status opendal_future_read_poll(struct opendal_future_read *future,
1666-
struct opendal_result_read *out);
1667-
1668-
/**
1669-
* \brief Non-blocking check whether the read future has completed.
1670-
*/
1671-
bool opendal_future_read_is_ready(const struct opendal_future_read *future);
1672-
16731530
/**
16741531
* \brief Cancel and free a read future without awaiting it.
16751532
*/
@@ -1682,22 +1539,8 @@ struct opendal_result_future_write opendal_async_operator_write(const struct ope
16821539
const char *path,
16831540
const struct opendal_bytes *bytes);
16841541

1685-
/**
1686-
* \brief Await an asynchronous write future.
1687-
*/
16881542
struct opendal_error *opendal_future_write_await(struct opendal_future_write *future);
16891543

1690-
/**
1691-
* \brief Non-blocking check whether a write future has completed and, if so, return any error.
1692-
*/
1693-
enum opendal_future_status opendal_future_write_poll(struct opendal_future_write *future,
1694-
struct opendal_error **error_out);
1695-
1696-
/**
1697-
* \brief Non-blocking check whether the write future has completed.
1698-
*/
1699-
bool opendal_future_write_is_ready(const struct opendal_future_write *future);
1700-
17011544
/**
17021545
* \brief Cancel and free a write future without awaiting it.
17031546
*/
@@ -1709,22 +1552,8 @@ void opendal_future_write_free(struct opendal_future_write *future);
17091552
struct opendal_result_future_delete opendal_async_operator_delete(const struct opendal_async_operator *op,
17101553
const char *path);
17111554

1712-
/**
1713-
* \brief Await an asynchronous delete future.
1714-
*/
17151555
struct opendal_error *opendal_future_delete_await(struct opendal_future_delete *future);
17161556

1717-
/**
1718-
* \brief Non-blocking check whether a delete future has completed and, if so, return any error.
1719-
*/
1720-
enum opendal_future_status opendal_future_delete_poll(struct opendal_future_delete *future,
1721-
struct opendal_error **error_out);
1722-
1723-
/**
1724-
* \brief Non-blocking check whether the delete future has completed.
1725-
*/
1726-
bool opendal_future_delete_is_ready(const struct opendal_future_delete *future);
1727-
17281557
/**
17291558
* \brief Cancel and free a delete future without awaiting it.
17301559
*/

0 commit comments

Comments
 (0)