Skip to content

Commit 9f82cbe

Browse files
committed
Update documentation
1 parent 1a81f8d commit 9f82cbe

File tree

10 files changed

+37
-8
lines changed

10 files changed

+37
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ with async/await features and support of writing native lua modules in Rust.
1818

1919
[package.metadata.docs.rs]
2020
features = ["lua53", "async", "send", "serialize"]
21+
rustdoc-args = ["--cfg", "docsrs"]
2122

2223
[workspace]
2324
members = [

src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ pub enum Error {
109109
///
110110
/// This error can happen either due to to being destructed in a previous __gc, or due to being
111111
/// destructed from exiting a `Lua::scope` call.
112+
///
113+
/// [`AnyUserData`]: struct.AnyUserData.html
112114
UserDataDestructed,
113115
/// An [`AnyUserData`] immutable borrow failed because it is already borrowed mutably.
114116
///
@@ -139,9 +141,11 @@ pub enum Error {
139141
},
140142
/// Serialization error.
141143
#[cfg(feature = "serialize")]
144+
#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))]
142145
SerializeError(StdString),
143146
/// Deserialization error.
144147
#[cfg(feature = "serialize")]
148+
#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))]
145149
DeserializeError(StdString),
146150
/// A custom error.
147151
///

src/function.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl<'lua> Function<'lua> {
119119
///
120120
/// [`AsyncThread`]: struct.AsyncThread.html
121121
#[cfg(feature = "async")]
122+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
122123
pub fn call_async<'fut, A, R>(&self, args: A) -> LocalBoxFuture<'fut, Result<R>>
123124
where
124125
'lua: 'fut,

src/lib.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
//!
2727
//! # Serde support
2828
//!
29-
//! The [`LuaSerdeExt`] trait implemented for [`Lua`] allow conversion from Rust types to Lua values
30-
//! and vice versa using serde. Any user defined data type that implements `serde::Serialize` or
31-
//! `serde::Deserialize` can be converted.
32-
//! For convenience, additional functionality to handle NULL values and arrays is provided.
29+
//! The [`LuaSerdeExt`] trait implemented for [`Lua`] allows conversion from Rust types to Lua values
30+
//! and vice versa using serde. Any user defined data type that implements [`serde::Serialize`] or
31+
//! [`serde::Deserialize`] can be converted.
32+
//! For convenience, additional functionality to handle `NULL` values and arrays is provided.
3333
//!
34-
//! The [`Value`] struct implements `serde::Serialize` trait to support serializing Lua values
34+
//! The [`Value`] enum implements [`serde::Serialize`] trait to support serializing Lua values
3535
//! (including [`UserData`]) into Rust values.
3636
//!
3737
//! Requires `feature = "serialize"`.
@@ -46,7 +46,7 @@
4646
//!
4747
//! # `Send` requirement
4848
//! By default `mlua` is `!Send`. This can be changed by enabling `feature = "send"` that adds `Send` requirement
49-
//! to `Function`s and [`UserData`].
49+
//! to [`Function`]s and [`UserData`].
5050
//!
5151
//! [Lua programming language]: https://www.lua.org/
5252
//! [`Lua`]: struct.Lua.html
@@ -57,14 +57,19 @@
5757
//! [`FromLua`]: trait.FromLua.html
5858
//! [`ToLuaMulti`]: trait.ToLuaMulti.html
5959
//! [`FromLuaMulti`]: trait.FromLuaMulti.html
60+
//! [`Function`]: struct.Function.html
6061
//! [`UserData`]: trait.UserData.html
6162
//! [`UserDataMethods`]: trait.UserDataMethods.html
62-
//! [`LuaSerdeExt`]: trait.LuaSerdeExt.html
63-
//! [`Value`]: struct.Value.html
63+
//! [`LuaSerdeExt`]: serde/trait.LuaSerdeExt.html
64+
//! [`Value`]: enum.Value.html
6465
//! [`create_async_function`]: struct.Lua.html#method.create_async_function
6566
//! [`call_async`]: struct.Function.html#method.call_async
6667
//! [`AsyncThread`]: struct.AsyncThread.html
6768
//! [`Future`]: ../futures_core/future/trait.Future.html
69+
//! [`serde::Serialize`]: https://docs.serde.rs/serde/ser/trait.Serialize.html
70+
//! [`serde::Deserialize`]: https://docs.serde.rs/serde/de/trait.Deserialize.html
71+
72+
#![cfg_attr(docsrs, feature(doc_cfg))]
6873

6974
// Deny warnings inside doc tests / examples. When this isn't present, rustdoc doesn't show *any*
7075
// warnings at all.
@@ -114,6 +119,7 @@ pub use crate::serde::LuaSerdeExt;
114119

115120
pub mod prelude;
116121
#[cfg(feature = "serialize")]
122+
#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))]
117123
pub mod serde;
118124

119125
// Re-export #[mlua_derive::lua_module].

src/lua.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub(crate) static EXTRA_REGISTRY_KEY: u8 = 0;
100100

101101
/// Requires `feature = "send"`
102102
#[cfg(feature = "send")]
103+
#[cfg_attr(docsrs, doc(cfg(feature = "send")))]
103104
unsafe impl Send for Lua {}
104105

105106
impl Drop for Lua {
@@ -957,6 +958,7 @@ impl Lua {
957958
/// [`Thread`]: struct.Thread.html
958959
/// [`AsyncThread`]: struct.AsyncThread.html
959960
#[cfg(feature = "async")]
961+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
960962
pub fn create_async_function<'lua, 'callback, A, R, F, FR>(
961963
&'lua self,
962964
func: F,
@@ -1006,6 +1008,7 @@ impl Lua {
10061008
///
10071009
/// Requires `feature = "serialize"`
10081010
#[cfg(feature = "serialize")]
1011+
#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))]
10091012
pub fn create_ser_userdata<T>(&self, data: T) -> Result<AnyUserData>
10101013
where
10111014
T: 'static + MaybeSend + UserData + Serialize,
@@ -1071,6 +1074,7 @@ impl Lua {
10711074
///
10721075
/// [`scope`]: #method.scope
10731076
#[cfg(feature = "async")]
1077+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
10741078
pub fn async_scope<'lua, 'scope, R, F, FR>(
10751079
&'lua self,
10761080
f: F,
@@ -1963,6 +1967,7 @@ impl<'lua, 'a> Chunk<'lua, 'a> {
19631967
///
19641968
/// [`Chunk::exec`]: struct.Chunk.html#method.exec
19651969
#[cfg(feature = "async")]
1970+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
19661971
pub fn exec_async<'fut>(self) -> LocalBoxFuture<'fut, Result<()>>
19671972
where
19681973
'lua: 'fut,
@@ -2002,6 +2007,7 @@ impl<'lua, 'a> Chunk<'lua, 'a> {
20022007
///
20032008
/// [`Chunk::eval`]: struct.Chunk.html#method.eval
20042009
#[cfg(feature = "async")]
2010+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
20052011
pub fn eval_async<'fut, R>(self) -> LocalBoxFuture<'fut, Result<R>>
20062012
where
20072013
'lua: 'fut,
@@ -2036,6 +2042,7 @@ impl<'lua, 'a> Chunk<'lua, 'a> {
20362042
///
20372043
/// [`Chunk::call`]: struct.Chunk.html#method.call
20382044
#[cfg(feature = "async")]
2045+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
20392046
pub fn call_async<'fut, A, R>(self, args: A) -> LocalBoxFuture<'fut, Result<R>>
20402047
where
20412048
'lua: 'fut,

src/scope.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
115115
/// [`Lua::scope`]: struct.Lua.html#method.scope
116116
/// [`Lua::async_scope`]: struct.Lua.html#method.async_scope
117117
#[cfg(feature = "async")]
118+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
118119
pub fn create_async_function<'callback, A, R, F, FR>(
119120
&'callback self,
120121
func: F,
@@ -164,6 +165,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> {
164165
/// [`Lua::create_ser_userdata`]: struct.Lua.html#method.create_ser_userdata
165166
/// [`Lua::scope`]: struct.Lua.html#method.scope
166167
#[cfg(feature = "serialize")]
168+
#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))]
167169
pub fn create_ser_userdata<T>(&self, data: T) -> Result<AnyUserData<'lua>>
168170
where
169171
T: 'static + UserData + Serialize,

src/serde/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! (De)Serialization support using serde.
2+
13
use std::os::raw::{c_int, c_void};
24
use std::ptr;
35

src/table.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ pub trait TableExt<'lua> {
550550
///
551551
/// This might invoke the `__index` metamethod.
552552
#[cfg(feature = "async")]
553+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
553554
fn call_async_method<'fut, K, A, R>(&self, key: K, args: A) -> LocalBoxFuture<'fut, Result<R>>
554555
where
555556
'lua: 'fut,
@@ -564,6 +565,7 @@ pub trait TableExt<'lua> {
564565
///
565566
/// This might invoke the `__index` metamethod.
566567
#[cfg(feature = "async")]
568+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
567569
fn call_async_function<'fut, K, A, R>(
568570
&self,
569571
key: K,

src/thread.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub struct Thread<'lua>(pub(crate) LuaRef<'lua>);
5252
/// [`Future`]: ../futures_core/future/trait.Future.html
5353
/// [`Stream`]: ../futures_core/stream/trait.Stream.html
5454
#[cfg(feature = "async")]
55+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
5556
#[derive(Debug)]
5657
pub struct AsyncThread<'lua, R> {
5758
thread: Thread<'lua>,
@@ -218,6 +219,7 @@ impl<'lua> Thread<'lua> {
218219
/// # }
219220
/// ```
220221
#[cfg(feature = "async")]
222+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
221223
pub fn into_async<A, R>(self, args: A) -> AsyncThread<'lua, R>
222224
where
223225
A: ToLuaMulti<'lua>,

src/userdata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ pub trait UserDataMethods<'lua, T: UserData> {
191191
///
192192
/// [`add_method`]: #method.add_method
193193
#[cfg(feature = "async")]
194+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
194195
fn add_async_method<S, A, R, M, MR>(&mut self, name: &S, method: M)
195196
where
196197
T: Clone,
@@ -237,6 +238,7 @@ pub trait UserDataMethods<'lua, T: UserData> {
237238
///
238239
/// [`add_function`]: #method.add_function
239240
#[cfg(feature = "async")]
241+
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
240242
fn add_async_function<S, A, R, F, FR>(&mut self, name: &S, function: F)
241243
where
242244
T: Clone,

0 commit comments

Comments
 (0)