diff --git a/Cargo.toml b/Cargo.toml index c551a7f..2d6bc7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ with async/await features and support of writing native lua modules in Rust. [package.metadata.docs.rs] features = ["lua53", "async", "send", "serialize"] +rustdoc-args = ["--cfg", "docsrs"] [workspace] members = [ diff --git a/src/error.rs b/src/error.rs index a4ff8b1..ad58307 100644 --- a/src/error.rs +++ b/src/error.rs @@ -109,6 +109,8 @@ pub enum Error { /// /// This error can happen either due to to being destructed in a previous __gc, or due to being /// destructed from exiting a `Lua::scope` call. + /// + /// [`AnyUserData`]: struct.AnyUserData.html UserDataDestructed, /// An [`AnyUserData`] immutable borrow failed because it is already borrowed mutably. /// @@ -139,9 +141,11 @@ pub enum Error { }, /// Serialization error. #[cfg(feature = "serialize")] + #[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] SerializeError(StdString), /// Deserialization error. #[cfg(feature = "serialize")] + #[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] DeserializeError(StdString), /// A custom error. /// diff --git a/src/function.rs b/src/function.rs index 45ad4e1..9a9c205 100644 --- a/src/function.rs +++ b/src/function.rs @@ -119,6 +119,7 @@ impl<'lua> Function<'lua> { /// /// [`AsyncThread`]: struct.AsyncThread.html #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub fn call_async<'fut, A, R>(&self, args: A) -> LocalBoxFuture<'fut, Result> where 'lua: 'fut, diff --git a/src/lib.rs b/src/lib.rs index cc5d0d8..23dd973 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,12 +26,12 @@ //! //! # Serde support //! -//! The [`LuaSerdeExt`] trait implemented for [`Lua`] allow conversion from Rust types to Lua values -//! and vice versa using serde. Any user defined data type that implements `serde::Serialize` or -//! `serde::Deserialize` can be converted. -//! For convenience, additional functionality to handle NULL values and arrays is provided. +//! The [`LuaSerdeExt`] trait implemented for [`Lua`] allows conversion from Rust types to Lua values +//! and vice versa using serde. Any user defined data type that implements [`serde::Serialize`] or +//! [`serde::Deserialize`] can be converted. +//! For convenience, additional functionality to handle `NULL` values and arrays is provided. //! -//! The [`Value`] struct implements `serde::Serialize` trait to support serializing Lua values +//! The [`Value`] enum implements [`serde::Serialize`] trait to support serializing Lua values //! (including [`UserData`]) into Rust values. //! //! Requires `feature = "serialize"`. @@ -46,7 +46,7 @@ //! //! # `Send` requirement //! By default `mlua` is `!Send`. This can be changed by enabling `feature = "send"` that adds `Send` requirement -//! to `Function`s and [`UserData`]. +//! to [`Function`]s and [`UserData`]. //! //! [Lua programming language]: https://www.lua.org/ //! [`Lua`]: struct.Lua.html @@ -57,14 +57,19 @@ //! [`FromLua`]: trait.FromLua.html //! [`ToLuaMulti`]: trait.ToLuaMulti.html //! [`FromLuaMulti`]: trait.FromLuaMulti.html +//! [`Function`]: struct.Function.html //! [`UserData`]: trait.UserData.html //! [`UserDataMethods`]: trait.UserDataMethods.html -//! [`LuaSerdeExt`]: trait.LuaSerdeExt.html -//! [`Value`]: struct.Value.html +//! [`LuaSerdeExt`]: serde/trait.LuaSerdeExt.html +//! [`Value`]: enum.Value.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 +//! [`serde::Serialize`]: https://docs.serde.rs/serde/ser/trait.Serialize.html +//! [`serde::Deserialize`]: https://docs.serde.rs/serde/de/trait.Deserialize.html + +#![cfg_attr(docsrs, feature(doc_cfg))] // Deny warnings inside doc tests / examples. When this isn't present, rustdoc doesn't show *any* // warnings at all. @@ -114,6 +119,7 @@ pub use crate::serde::LuaSerdeExt; pub mod prelude; #[cfg(feature = "serialize")] +#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] pub mod serde; // Re-export #[mlua_derive::lua_module]. diff --git a/src/lua.rs b/src/lua.rs index 3d3a93b..8720c88 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -100,6 +100,7 @@ pub(crate) static EXTRA_REGISTRY_KEY: u8 = 0; /// Requires `feature = "send"` #[cfg(feature = "send")] +#[cfg_attr(docsrs, doc(cfg(feature = "send")))] unsafe impl Send for Lua {} impl Drop for Lua { @@ -957,6 +958,7 @@ impl Lua { /// [`Thread`]: struct.Thread.html /// [`AsyncThread`]: struct.AsyncThread.html #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub fn create_async_function<'lua, 'callback, A, R, F, FR>( &'lua self, func: F, @@ -1006,6 +1008,7 @@ impl Lua { /// /// Requires `feature = "serialize"` #[cfg(feature = "serialize")] + #[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] pub fn create_ser_userdata(&self, data: T) -> Result where T: 'static + MaybeSend + UserData + Serialize, @@ -1071,6 +1074,7 @@ impl Lua { /// /// [`scope`]: #method.scope #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub fn async_scope<'lua, 'scope, R, F, FR>( &'lua self, f: F, @@ -1963,6 +1967,7 @@ impl<'lua, 'a> Chunk<'lua, 'a> { /// /// [`Chunk::exec`]: struct.Chunk.html#method.exec #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub fn exec_async<'fut>(self) -> LocalBoxFuture<'fut, Result<()>> where 'lua: 'fut, @@ -2002,6 +2007,7 @@ impl<'lua, 'a> Chunk<'lua, 'a> { /// /// [`Chunk::eval`]: struct.Chunk.html#method.eval #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub fn eval_async<'fut, R>(self) -> LocalBoxFuture<'fut, Result> where 'lua: 'fut, @@ -2036,6 +2042,7 @@ impl<'lua, 'a> Chunk<'lua, 'a> { /// /// [`Chunk::call`]: struct.Chunk.html#method.call #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub fn call_async<'fut, A, R>(self, args: A) -> LocalBoxFuture<'fut, Result> where 'lua: 'fut, diff --git a/src/scope.rs b/src/scope.rs index bfdae42..4965a1f 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -115,6 +115,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { /// [`Lua::scope`]: struct.Lua.html#method.scope /// [`Lua::async_scope`]: struct.Lua.html#method.async_scope #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub fn create_async_function<'callback, A, R, F, FR>( &'callback self, func: F, @@ -164,6 +165,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { /// [`Lua::create_ser_userdata`]: struct.Lua.html#method.create_ser_userdata /// [`Lua::scope`]: struct.Lua.html#method.scope #[cfg(feature = "serialize")] + #[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] pub fn create_ser_userdata(&self, data: T) -> Result> where T: 'static + UserData + Serialize, diff --git a/src/serde/mod.rs b/src/serde/mod.rs index a476d8f..3163d3d 100644 --- a/src/serde/mod.rs +++ b/src/serde/mod.rs @@ -1,3 +1,5 @@ +//! (De)Serialization support using serde. + use std::os::raw::{c_int, c_void}; use std::ptr; diff --git a/src/table.rs b/src/table.rs index f0a4acd..f294faf 100644 --- a/src/table.rs +++ b/src/table.rs @@ -550,6 +550,7 @@ pub trait TableExt<'lua> { /// /// This might invoke the `__index` metamethod. #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] fn call_async_method<'fut, K, A, R>(&self, key: K, args: A) -> LocalBoxFuture<'fut, Result> where 'lua: 'fut, @@ -564,6 +565,7 @@ pub trait TableExt<'lua> { /// /// This might invoke the `__index` metamethod. #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] fn call_async_function<'fut, K, A, R>( &self, key: K, diff --git a/src/thread.rs b/src/thread.rs index 661abd3..f26eca1 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -52,6 +52,7 @@ pub struct Thread<'lua>(pub(crate) LuaRef<'lua>); /// [`Future`]: ../futures_core/future/trait.Future.html /// [`Stream`]: ../futures_core/stream/trait.Stream.html #[cfg(feature = "async")] +#[cfg_attr(docsrs, doc(cfg(feature = "async")))] #[derive(Debug)] pub struct AsyncThread<'lua, R> { thread: Thread<'lua>, @@ -218,6 +219,7 @@ impl<'lua> Thread<'lua> { /// # } /// ``` #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub fn into_async(self, args: A) -> AsyncThread<'lua, R> where A: ToLuaMulti<'lua>, diff --git a/src/userdata.rs b/src/userdata.rs index ae6ff38..a6131a1 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -191,6 +191,7 @@ pub trait UserDataMethods<'lua, T: UserData> { /// /// [`add_method`]: #method.add_method #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] fn add_async_method(&mut self, name: &S, method: M) where T: Clone, @@ -237,6 +238,7 @@ pub trait UserDataMethods<'lua, T: UserData> { /// /// [`add_function`]: #method.add_function #[cfg(feature = "async")] + #[cfg_attr(docsrs, doc(cfg(feature = "async")))] fn add_async_function(&mut self, name: &S, function: F) where T: Clone,