From bf24824c61df0a00c4694cbfe19dc18a24b2e6c3 Mon Sep 17 00:00:00 2001 From: Jerel Unruh Date: Mon, 3 May 2021 14:21:24 -0500 Subject: [PATCH 1/2] Extend the book's async example to show multiple calls to rust::Fn to produce a stream --- book/src/async.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/book/src/async.md b/book/src/async.md index b4c696a36..50e3f39db 100644 --- a/book/src/async.md +++ b/book/src/async.md @@ -84,3 +84,25 @@ void shim_doThing( }); } ``` + +### Streams + +The async approach can be extended to support streaming data as well using a channel such as [`futures::channel::mpsc::unbounded`] instead of oneshot and passing `DoThingContext` to the closure as a reference: + +[`futures::channel::mpsc::unbounded`]: https://docs.rs/futures/0.3.8/futures/channel/mpsc/fn.unbounded.html + +```cpp +// bridge_shim.cc + +#include "path/to/bridge.rs.h" +#include "rust/cxx.h" + +void shim_doThing( + Arg arg, + rust::Fn done, + rust::Box ctx) noexcept { + done(*ctx, std::move(res)); + done(*ctx, std::move(res)); + done(*ctx, std::move(res)); +} +``` From f39f1f1dde21e298c41169bd0262e5713959193f Mon Sep 17 00:00:00 2001 From: Jerel Unruh Date: Mon, 3 May 2021 14:39:30 -0500 Subject: [PATCH 2/2] Improved grammar --- book/src/async.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/async.md b/book/src/async.md index 50e3f39db..9482e92d9 100644 --- a/book/src/async.md +++ b/book/src/async.md @@ -87,7 +87,7 @@ void shim_doThing( ### Streams -The async approach can be extended to support streaming data as well using a channel such as [`futures::channel::mpsc::unbounded`] instead of oneshot and passing `DoThingContext` to the closure as a reference: +The async example above can be extended to support streaming data as well using a channel such as [`futures::channel::mpsc::unbounded`] instead of oneshot and passing `DoThingContext` to the closure as a reference: [`futures::channel::mpsc::unbounded`]: https://docs.rs/futures/0.3.8/futures/channel/mpsc/fn.unbounded.html