Update documentation

This commit is contained in:
Alex Orlenko 2020-04-20 01:52:01 +01:00
parent 4e19ae6ccf
commit 0efa0fcb6a
4 changed files with 19 additions and 3 deletions

View File

@ -18,7 +18,7 @@ modules in Rust.
## Usage ## 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`. 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`.

View File

@ -92,7 +92,7 @@ impl<'lua> Function<'lua> {
/// Returns a Feature that, when polled, calls `self`, passing `args` as function arguments, /// Returns a Feature that, when polled, calls `self`, passing `args` as function arguments,
/// and drives the execution. /// and drives the execution.
/// ///
/// Internaly it wraps the function to an AsyncThread. /// Internaly it wraps the function to an [`AsyncThread`].
/// ///
/// # Examples /// # Examples
/// ///
@ -103,6 +103,7 @@ impl<'lua> Function<'lua> {
/// # #[tokio::main] /// # #[tokio::main]
/// # async fn main() -> Result<()> { /// # async fn main() -> Result<()> {
/// # let lua = Lua::new(); /// # let lua = Lua::new();
///
/// let sleep = lua.create_async_function(move |_lua, n: u64| async move { /// let sleep = lua.create_async_function(move |_lua, n: u64| async move {
/// Delay::new(Duration::from_millis(n)).await; /// Delay::new(Duration::from_millis(n)).await;
/// Ok(()) /// Ok(())
@ -113,6 +114,8 @@ impl<'lua> Function<'lua> {
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
///
/// [`AsyncThread`]: struct.AsyncThread.html
#[cfg(feature = "async")] #[cfg(feature = "async")]
pub fn call_async<'fut, A, R>(&self, args: A) -> LocalBoxFuture<'fut, Result<R>> pub fn call_async<'fut, A, R>(&self, args: A) -> LocalBoxFuture<'fut, Result<R>>
where where

View File

@ -24,6 +24,12 @@
//! The [`UserData`] trait can be implemented by user-defined types to make them available to Lua. //! 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. //! 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 programming language]: https://www.lua.org/
//! [`Lua`]: struct.Lua.html //! [`Lua`]: struct.Lua.html
//! [executing]: struct.Lua.html#method.exec //! [executing]: struct.Lua.html#method.exec
@ -35,6 +41,10 @@
//! [`FromLuaMulti`]: trait.FromLuaMulti.html //! [`FromLuaMulti`]: trait.FromLuaMulti.html
//! [`UserData`]: trait.UserData.html //! [`UserData`]: trait.UserData.html
//! [`UserDataMethods`]: trait.UserDataMethods.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* // Deny warnings inside doc tests / examples. When this isn't present, rustdoc doesn't show *any*
// warnings at all. // warnings at all.

View File

@ -45,7 +45,10 @@ pub enum ThreadStatus {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Thread<'lua>(pub(crate) LuaRef<'lua>); 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")] #[cfg(feature = "async")]
#[derive(Debug)] #[derive(Debug)]
pub struct AsyncThread<'lua, R> { pub struct AsyncThread<'lua, R> {