diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2020-04-20 01:52:01 +0100 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2020-04-20 01:52:01 +0100 |
commit | 0efa0fcb6a642c2086dd8fb72c8d6d817106d3c4 (patch) | |
tree | 48904e7d2df7d42eb391a1b0bc4c038fb170a521 | |
parent | 4e19ae6ccfc992bc4b32e8c3198cf5c35244e395 (diff) | |
download | mlua-0efa0fcb6a642c2086dd8fb72c8d6d817106d3c4.zip |
Update documentation
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/function.rs | 5 | ||||
-rw-r--r-- | src/lib.rs | 10 | ||||
-rw-r--r-- | src/thread.rs | 5 |
4 files changed, 19 insertions, 3 deletions
@@ -18,7 +18,7 @@ modules in Rust. ## Usage -### Async +### Async/await support Starting from 0.3, mlua supports async/await for all Lua versions. This works using Lua [coroutines](https://www.lua.org/manual/5.3/manual.html#2.6) and require running [Thread](https://docs.rs/mlua/latest/mlua/struct.Thread.html) along with enabling `async` feature in `Cargo.toml`. diff --git a/src/function.rs b/src/function.rs index 7151c34..3589b2b 100644 --- a/src/function.rs +++ b/src/function.rs @@ -92,7 +92,7 @@ impl<'lua> Function<'lua> { /// Returns a Feature that, when polled, calls `self`, passing `args` as function arguments, /// and drives the execution. /// - /// Internaly it wraps the function to an AsyncThread. + /// Internaly it wraps the function to an [`AsyncThread`]. /// /// # Examples /// @@ -103,6 +103,7 @@ impl<'lua> Function<'lua> { /// # #[tokio::main] /// # async fn main() -> Result<()> { /// # let lua = Lua::new(); + /// /// let sleep = lua.create_async_function(move |_lua, n: u64| async move { /// Delay::new(Duration::from_millis(n)).await; /// Ok(()) @@ -113,6 +114,8 @@ impl<'lua> Function<'lua> { /// # Ok(()) /// # } /// ``` + /// + /// [`AsyncThread`]: struct.AsyncThread.html #[cfg(feature = "async")] pub fn call_async<'fut, A, R>(&self, args: A) -> LocalBoxFuture<'fut, Result<R>> where @@ -24,6 +24,12 @@ //! The [`UserData`] trait can be implemented by user-defined types to make them available to Lua. //! Methods and operators to be used from Lua can be added using the [`UserDataMethods`] API. //! +//! # Async/await support +//! +//! The [`create_async_function`] allows creating non-blocking functions that returns [`Future`]. +//! Lua code with async capabilities can be executed by [`call_async`] family of functions or polling +//! [`AsyncThread`] using any runtime (eg. Tokio). +//! //! [Lua programming language]: https://www.lua.org/ //! [`Lua`]: struct.Lua.html //! [executing]: struct.Lua.html#method.exec @@ -35,6 +41,10 @@ //! [`FromLuaMulti`]: trait.FromLuaMulti.html //! [`UserData`]: trait.UserData.html //! [`UserDataMethods`]: trait.UserDataMethods.html +//! [`create_async_function`]: struct.Lua.html#method.create_async_function +//! [`call_async`]: struct.Function.html#method.call_async +//! [`AsyncThread`]: struct.AsyncThread.html +//! [`Future`]: ../futures_core/future/trait.Future.html // Deny warnings inside doc tests / examples. When this isn't present, rustdoc doesn't show *any* // warnings at all. diff --git a/src/thread.rs b/src/thread.rs index ce1dd57..ebbed37 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -45,7 +45,10 @@ pub enum ThreadStatus { #[derive(Clone, Debug)] pub struct Thread<'lua>(pub(crate) LuaRef<'lua>); -/// Thread (coroutine) representation as an async Future or Stream. +/// Thread (coroutine) representation as an async [`Future`] or [`Stream`]. +/// +/// [`Future`]: ../futures_core/future/trait.Future.html +/// [`Stream`]: ../futures_core/stream/trait.Stream.html #[cfg(feature = "async")] #[derive(Debug)] pub struct AsyncThread<'lua, R> { |