summaryrefslogtreecommitdiffstats
path: root/vendor/cxx/book/src/async.md
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/cxx/book/src/async.md
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/cxx/book/src/async.md')
-rw-r--r--vendor/cxx/book/src/async.md86
1 files changed, 0 insertions, 86 deletions
diff --git a/vendor/cxx/book/src/async.md b/vendor/cxx/book/src/async.md
deleted file mode 100644
index b4c696a36..000000000
--- a/vendor/cxx/book/src/async.md
+++ /dev/null
@@ -1,86 +0,0 @@
-{{#title Async functions — Rust ♡ C++}}
-# Async functions
-
-Direct FFI of async functions is absolutely in scope for CXX (on C++20 and up)
-but is not implemented yet in the current release. We are aiming for an
-implementation that is as easy as:
-
-```rust,noplayground
-#[cxx::bridge]
-mod ffi {
- unsafe extern "C++" {
- async fn doThing(arg: Arg) -> Ret;
- }
-}
-```
-
-```cpp,hidelines
-rust::Future<Ret> doThing(Arg arg) {
- auto v1 = co_await f();
- auto v2 = co_await g(arg);
- co_return v1 + v2;
-}
-```
-
-## Workaround
-
-For now the recommended approach is to handle the return codepath over a oneshot
-channel (such as [`futures::channel::oneshot`]) represented in an opaque Rust
-type on the FFI.
-
-[`futures::channel::oneshot`]: https://docs.rs/futures/0.3.8/futures/channel/oneshot/index.html
-
-```rust,noplayground
-// bridge.rs
-
-use futures::channel::oneshot;
-
-#[cxx::bridge]
-mod ffi {
- extern "Rust" {
- type DoThingContext;
- }
-
- unsafe extern "C++" {
- include!("path/to/bridge_shim.h");
-
- fn shim_doThing(
- arg: Arg,
- done: fn(Box<DoThingContext>, ret: Ret),
- ctx: Box<DoThingContext>,
- );
- }
-}
-
-struct DoThingContext(oneshot::Sender<Ret>);
-
-pub async fn do_thing(arg: Arg) -> Ret {
- let (tx, rx) = oneshot::channel();
- let context = Box::new(DoThingContext(tx));
-
- ffi::shim_doThing(
- arg,
- |context, ret| { let _ = context.0.send(ret); },
- context,
- );
-
- rx.await.unwrap()
-}
-```
-
-```cpp
-// bridge_shim.cc
-
-#include "path/to/bridge.rs.h"
-#include "rust/cxx.h"
-
-void shim_doThing(
- Arg arg,
- rust::Fn<void(rust::Box<DoThingContext> ctx, Ret ret)> done,
- rust::Box<DoThingContext> ctx) noexcept {
- doThing(arg)
- .then([done, ctx(std::move(ctx))](auto &&res) mutable {
- (*done)(std::move(ctx), std::move(res));
- });
-}
-```