Skip to content

Commit 93a1a55

Browse files
committed
Update docs
1 parent a020b2b commit 93a1a55

File tree

20 files changed

+298
-326
lines changed

20 files changed

+298
-326
lines changed

src/chunk.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::traits::{FromLuaMulti, IntoLuaMulti};
1414
/// Trait for types [loadable by Lua] and convertible to a [`Chunk`]
1515
///
1616
/// [loadable by Lua]: https://www.lua.org/manual/5.4/manual.html#3.3.2
17-
/// [`Chunk`]: crate::Chunk
1817
pub trait AsChunk<'a> {
1918
/// Returns optional chunk name
2019
fn name(&self) -> Option<StdString> {
@@ -95,8 +94,6 @@ impl AsChunk<'static> for PathBuf {
9594
}
9695

9796
/// Returned from [`Lua::load`] and is used to finalize loading and executing Lua main chunks.
98-
///
99-
/// [`Lua::load`]: crate::Lua::load
10097
#[must_use = "`Chunk`s do nothing unless one of `exec`, `eval`, `call`, or `into_function` are called on them"]
10198
pub struct Chunk<'a> {
10299
pub(crate) lua: WeakLua,
@@ -241,7 +238,7 @@ impl Compiler {
241238

242239
/// Compiles the `source` into bytecode.
243240
///
244-
/// Returns `Error::SyntaxError` if the source code is invalid.
241+
/// Returns [`Error::SyntaxError`] if the source code is invalid.
245242
pub fn compile(&self, source: impl AsRef<[u8]>) -> Result<Vec<u8>> {
246243
use std::os::raw::c_int;
247244
use std::ptr;
@@ -361,7 +358,7 @@ impl<'a> Chunk<'a> {
361358
///
362359
/// Requires `feature = "async"`
363360
///
364-
/// [`exec`]: #method.exec
361+
/// [`exec`]: Chunk::exec
365362
#[cfg(feature = "async")]
366363
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
367364
pub async fn exec_async(self) -> Result<()> {
@@ -393,7 +390,7 @@ impl<'a> Chunk<'a> {
393390
///
394391
/// Requires `feature = "async"`
395392
///
396-
/// [`eval`]: #method.eval
393+
/// [`eval`]: Chunk::eval
397394
#[cfg(feature = "async")]
398395
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
399396
pub async fn eval_async<R>(self) -> Result<R>
@@ -422,7 +419,7 @@ impl<'a> Chunk<'a> {
422419
///
423420
/// Requires `feature = "async"`
424421
///
425-
/// [`call`]: #method.call
422+
/// [`call`]: Chunk::call
426423
#[cfg(feature = "async")]
427424
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
428425
pub async fn call_async<R>(self, args: impl IntoLuaMulti) -> Result<R>
@@ -432,7 +429,7 @@ impl<'a> Chunk<'a> {
432429
self.into_function()?.call_async(args).await
433430
}
434431

435-
/// Load this chunk into a regular `Function`.
432+
/// Load this chunk into a regular [`Function`].
436433
///
437434
/// This simply compiles the chunk without actually executing it.
438435
#[cfg_attr(not(feature = "luau"), allow(unused_mut))]

src/error.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ pub enum Error {
6161
///
6262
/// Due to the way `mlua` works, it should not be directly possible to run out of stack space
6363
/// during normal use. The only way that this error can be triggered is if a `Function` is
64-
/// called with a huge number of arguments, or a rust callback returns a huge number of return
64+
/// called with a huge number of arguments, or a Rust callback returns a huge number of return
6565
/// values.
6666
StackError,
67-
/// Too many arguments to `Function::bind`.
67+
/// Too many arguments to [`Function::bind`].
68+
///
69+
/// [`Function::bind`]: crate::Function::bind
6870
BindError,
6971
/// Bad argument received from Lua (usually when calling a function).
7072
///

src/function.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ impl Function {
389389
/// If `strip` is true, the binary representation may not include all debug information
390390
/// about the function, to save space.
391391
///
392-
/// For Luau a [Compiler] can be used to compile Lua chunks to bytecode.
392+
/// For Luau a [`Compiler`] can be used to compile Lua chunks to bytecode.
393393
///
394-
/// [Compiler]: crate::chunk::Compiler
394+
/// [`Compiler`]: crate::chunk::Compiler
395395
#[cfg(not(feature = "luau"))]
396396
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
397397
pub fn dump(&self, strip: bool) -> Vec<u8> {
@@ -490,10 +490,10 @@ impl Function {
490490
///
491491
/// Copies the function prototype and all its upvalues to the
492492
/// newly created function.
493-
///
494493
/// This function returns shallow clone (same handle) for Rust/C functions.
494+
///
495495
/// Requires `feature = "luau"`
496-
#[cfg(feature = "luau")]
496+
#[cfg(any(feature = "luau", doc))]
497497
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
498498
pub fn deep_clone(&self) -> Self {
499499
let lua = self.0.lua.lock();

src/hook.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use crate::util::{linenumber_to_usize, ptr_to_lossy_str, ptr_to_str};
1616
/// The `Debug` structure is provided as a parameter to the hook function set with
1717
/// [`Lua::set_hook`]. You may call the methods on this structure to retrieve information about the
1818
/// Lua code executing at the time that the hook function was called. Further information can be
19-
/// found in the Lua [documentation][lua_doc].
19+
/// found in the Lua [documentation].
2020
///
21-
/// [lua_doc]: https://www.lua.org/manual/5.4/manual.html#lua_Debug
21+
/// [documentation]: https://www.lua.org/manual/5.4/manual.html#lua_Debug
2222
/// [`Lua::set_hook`]: crate::Lua::set_hook
2323
pub struct Debug<'a> {
2424
lua: EitherLua<'a>,
@@ -66,7 +66,7 @@ impl<'a> Debug<'a> {
6666

6767
/// Returns the specific event that triggered the hook.
6868
///
69-
/// For [Lua 5.1] `DebugEvent::TailCall` is used for return events to indicate a return
69+
/// For [Lua 5.1] [`DebugEvent::TailCall`] is used for return events to indicate a return
7070
/// from a function that did a tail call.
7171
///
7272
/// [Lua 5.1]: https://www.lua.org/manual/5.1/manual.html#pdf-LUA_HOOKTAILRET

src/lib.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,32 @@
3232
//! [`serde::Serialize`] or [`serde::Deserialize`] can be converted.
3333
//! For convenience, additional functionality to handle `NULL` values and arrays is provided.
3434
//!
35-
//! The [`Value`] enum implements [`serde::Serialize`] trait to support serializing Lua values
36-
//! (including [`UserData`]) into Rust values.
35+
//! The [`Value`] enum and other types implement [`serde::Serialize`] trait to support serializing
36+
//! Lua values into Rust values.
3737
//!
3838
//! Requires `feature = "serialize"`.
3939
//!
4040
//! # Async/await support
4141
//!
42-
//! The [`create_async_function`] allows creating non-blocking functions that returns [`Future`].
43-
//! Lua code with async capabilities can be executed by [`call_async`] family of functions or
44-
//! polling [`AsyncThread`] using any runtime (eg. Tokio).
42+
//! The [`Lua::create_async_function`] allows creating non-blocking functions that returns
43+
//! [`Future`]. Lua code with async capabilities can be executed by [`Function::call_async`] family
44+
//! of functions or polling [`AsyncThread`] using any runtime (eg. Tokio).
4545
//!
4646
//! Requires `feature = "async"`.
4747
//!
48-
//! # `Send` requirement
48+
//! # `Send` and `Sync` support
49+
//!
4950
//! By default `mlua` is `!Send`. This can be changed by enabling `feature = "send"` that adds
50-
//! `Send` requirement to [`Function`]s and [`UserData`].
51+
//! `Send` requirement to Rust functions and [`UserData`] types.
52+
//!
53+
//! In this case [`Lua`] object and their types can be send or used from other threads. Internally
54+
//! access to Lua VM is synchronized using a reentrant mutex that can be locked many times within
55+
//! the same thread.
5156
//!
5257
//! [Lua programming language]: https://www.lua.org/
53-
//! [`Lua`]: crate::Lua
5458
//! [executing]: crate::Chunk::exec
5559
//! [evaluating]: crate::Chunk::eval
5660
//! [globals]: crate::Lua::globals
57-
//! [`IntoLua`]: crate::IntoLua
58-
//! [`FromLua`]: crate::FromLua
59-
//! [`IntoLuaMulti`]: crate::IntoLuaMulti
60-
//! [`FromLuaMulti`]: crate::FromLuaMulti
61-
//! [`Function`]: crate::Function
62-
//! [`UserData`]: crate::UserData
63-
//! [`UserDataFields`]: crate::UserDataFields
64-
//! [`UserDataMethods`]: crate::UserDataMethods
65-
//! [`LuaSerdeExt`]: crate::LuaSerdeExt
66-
//! [`Value`]: crate::Value
67-
//! [`create_async_function`]: crate::Lua::create_async_function
68-
//! [`call_async`]: crate::Function::call_async
69-
//! [`AsyncThread`]: crate::AsyncThread
7061
//! [`Future`]: std::future::Future
7162
//! [`serde::Serialize`]: https://docs.serde.rs/serde/ser/trait.Serialize.html
7263
//! [`serde::Deserialize`]: https://docs.serde.rs/serde/de/trait.Deserialize.html
@@ -199,10 +190,6 @@ extern crate mlua_derive;
199190
/// - The `//` (floor division) operator is unusable, as its start a comment.
200191
///
201192
/// Everything else should work.
202-
///
203-
/// [`AsChunk`]: crate::AsChunk
204-
/// [`UserData`]: crate::UserData
205-
/// [`IntoLua`]: crate::IntoLua
206193
#[cfg(feature = "macros")]
207194
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
208195
pub use mlua_derive::chunk;

src/multi.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::traits::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti};
1111
use crate::util::check_stack;
1212
use crate::value::{Nil, Value};
1313

14-
/// Result is convertible to `MultiValue` following the common Lua idiom of returning the result
14+
/// Result is convertible to [`MultiValue`] following the common Lua idiom of returning the result
1515
/// on success, or in the case of an error, returning `nil` and an error message.
1616
impl<T: IntoLua, E: IntoLua> IntoLuaMulti for StdResult<T, E> {
1717
#[inline]
@@ -203,9 +203,6 @@ impl FromLuaMulti for MultiValue {
203203
/// # Ok(())
204204
/// # }
205205
/// ```
206-
///
207-
/// [`FromLua`]: crate::FromLua
208-
/// [`MultiValue`]: crate::MultiValue
209206
#[derive(Debug, Clone)]
210207
pub struct Variadic<T>(Vec<T>);
211208

src/scope.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,15 @@ impl<'scope, 'env: 'scope> Scope<'scope, 'env> {
148148
/// [`Lua::scope`] for more details.
149149
///
150150
/// The main limitation that comes from using non-'static userdata is that the produced userdata
151-
/// will no longer have a `TypeId` associated with it, because `TypeId` can only work for
151+
/// will no longer have a [`TypeId`] associated with it, because [`TypeId`] can only work for
152152
/// `'static` types. This means that it is impossible, once the userdata is created, to get a
153-
/// reference to it back *out* of an `AnyUserData` handle. This also implies that the
153+
/// reference to it back *out* of an [`AnyUserData`] handle. This also implies that the
154154
/// "function" type methods that can be added via [`UserDataMethods`] (the ones that accept
155-
/// `AnyUserData` as a first parameter) are vastly less useful. Also, there is no way to re-use
155+
/// [`AnyUserData`] as a first parameter) are vastly less useful. Also, there is no way to re-use
156156
/// a single metatable for multiple non-'static types, so there is a higher cost associated with
157157
/// creating the userdata metatable each time a new userdata is created.
158158
///
159+
/// [`TypeId`]: std::any::TypeId
159160
/// [`UserDataMethods`]: crate::UserDataMethods
160161
pub fn create_userdata<T>(&'scope self, data: T) -> Result<AnyUserData>
161162
where

src/serde/de.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ impl Options {
9494
}
9595

9696
impl Deserializer {
97-
/// Creates a new Lua Deserializer for the `Value`.
97+
/// Creates a new Lua Deserializer for the [`Value`].
9898
pub fn new(value: Value) -> Self {
9999
Self::new_with_options(value, Options::default())
100100
}
101101

102-
/// Creates a new Lua Deserializer for the `Value` with custom options.
102+
/// Creates a new Lua Deserializer for the [`Value`] with custom options.
103103
pub fn new_with_options(value: Value, options: Options) -> Self {
104104
Deserializer {
105105
value,

src/serde/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ pub trait LuaSerdeExt: Sealed {
106106
///
107107
/// Requires `feature = "serialize"`
108108
///
109-
/// [`Value`]: crate::Value
110-
///
111109
/// # Example
112110
///
113111
/// ```
@@ -133,8 +131,6 @@ pub trait LuaSerdeExt: Sealed {
133131
///
134132
/// Requires `feature = "serialize"`
135133
///
136-
/// [`Value`]: crate::Value
137-
///
138134
/// # Example
139135
///
140136
/// ```
@@ -164,8 +160,6 @@ pub trait LuaSerdeExt: Sealed {
164160
///
165161
/// Requires `feature = "serialize"`
166162
///
167-
/// [`Value`]: crate::Value
168-
///
169163
/// # Example
170164
///
171165
/// ```

0 commit comments

Comments
 (0)