From ec1fa040853ac3be72e2a3e8330e121f23d457e3 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Fri, 25 Mar 2022 00:23:35 +0000 Subject: [PATCH] Update docs --- src/chunk.rs | 19 ++++++++++--------- src/error.rs | 3 ++- src/function.rs | 1 + src/hook.rs | 3 +++ src/lib.rs | 5 +++-- src/lua.rs | 6 +++++- src/serde/mod.rs | 1 + src/stdlib.rs | 8 +++++--- src/table.rs | 2 ++ src/userdata.rs | 6 ------ src/value.rs | 3 ++- 11 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/chunk.rs b/src/chunk.rs index 3bb7c18..cae1781 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -64,7 +64,8 @@ pub enum ChunkMode { } /// Luau compiler -#[cfg(feature = "luau")] +#[cfg(any(feature = "luau", doc))] +#[cfg_attr(docsrs, doc(cfg(feature = "luau")))] #[derive(Clone, Copy, Debug)] pub struct Compiler { optimization_level: u8, @@ -72,7 +73,7 @@ pub struct Compiler { coverage_level: u8, } -#[cfg(feature = "luau")] +#[cfg(any(feature = "luau", doc))] impl Default for Compiler { fn default() -> Self { // Defaults are taken from luacode.h @@ -84,7 +85,7 @@ impl Default for Compiler { } } -#[cfg(feature = "luau")] +#[cfg(any(feature = "luau", doc))] impl Compiler { /// Creates Luau compiler instance with default options pub fn new() -> Self { @@ -97,7 +98,6 @@ impl Compiler { /// 0 - no optimization /// 1 - baseline optimization level that doesn't prevent debuggability (default) /// 2 - includes optimizations that harm debuggability such as inlining - #[cfg(feature = "luau")] pub fn set_optimization_level(mut self, level: u8) -> Self { self.optimization_level = level; self @@ -109,7 +109,6 @@ impl Compiler { /// 0 - no debugging support /// 1 - line info & function names only; sufficient for backtraces (default) /// 2 - full debug info with local & upvalue names; necessary for debugger - #[cfg(feature = "luau")] pub fn set_debug_level(mut self, level: u8) -> Self { self.debug_level = level; self @@ -121,7 +120,6 @@ impl Compiler { /// 0 - no code coverage support (default) /// 1 - statement coverage /// 2 - statement and expression coverage (verbose) - #[cfg(feature = "luau")] pub fn set_coverage_level(mut self, level: u8) -> Self { self.coverage_level = level; self @@ -190,7 +188,8 @@ impl<'lua, 'a> Chunk<'lua, 'a> { /// See [`Compiler::set_optimization_level`] for details. /// /// Requires `feature = "luau` - #[cfg(feature = "luau")] + #[cfg(any(feature = "luau", doc))] + #[cfg_attr(docsrs, doc(cfg(feature = "luau")))] pub fn set_optimization_level(mut self, level: u8) -> Self { self.compiler .get_or_insert_with(Default::default) @@ -203,7 +202,8 @@ impl<'lua, 'a> Chunk<'lua, 'a> { /// See [`Compiler::set_debug_level`] for details. /// /// Requires `feature = "luau` - #[cfg(feature = "luau")] + #[cfg(any(feature = "luau", doc))] + #[cfg_attr(docsrs, doc(cfg(feature = "luau")))] pub fn set_debug_level(mut self, level: u8) -> Self { self.compiler .get_or_insert_with(Default::default) @@ -216,7 +216,8 @@ impl<'lua, 'a> Chunk<'lua, 'a> { /// See [`Compiler::set_coverage_level`] for details. /// /// Requires `feature = "luau` - #[cfg(feature = "luau")] + #[cfg(any(feature = "luau", doc))] + #[cfg_attr(docsrs, doc(cfg(feature = "luau")))] pub fn set_coverage_level(mut self, level: u8) -> Self { self.compiler .get_or_insert_with(Default::default) diff --git a/src/error.rs b/src/error.rs index 760c49b..e50a2b2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -37,7 +37,8 @@ pub enum Error { /// Lua garbage collector error, aka `LUA_ERRGCMM`. /// /// The Lua VM returns this error when there is an error running a `__gc` metamethod. - #[cfg(any(feature = "lua53", feature = "lua52"))] + #[cfg(any(feature = "lua53", feature = "lua52", doc))] + #[cfg_attr(docsrs, doc(cfg(any(feature = "lua53", feature = "lua52"))))] GarbageCollectorError(StdString), /// Potentially unsafe action in safe mode. SafetyError(StdString), diff --git a/src/function.rs b/src/function.rs index 8c35ef1..60ee7ea 100644 --- a/src/function.rs +++ b/src/function.rs @@ -214,6 +214,7 @@ impl<'lua> Function<'lua> { /// If `strip` is true, the binary representation may not include all debug information /// about the function, to save space. #[cfg(not(feature = "luau"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub fn dump(&self, strip: bool) -> Vec { use std::os::raw::c_void; use std::slice; diff --git a/src/hook.rs b/src/hook.rs index 88bfd1a..44d4136 100644 --- a/src/hook.rs +++ b/src/hook.rs @@ -48,6 +48,7 @@ impl<'lua> Debug<'lua> { /// /// [Lua 5.1]: https://www.lua.org/manual/5.1/manual.html#pdf-LUA_HOOKTAILRET #[cfg(not(feature = "luau"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub fn event(&self) -> DebugEvent { unsafe { match (*self.ar.get()).event { @@ -131,6 +132,7 @@ impl<'lua> Debug<'lua> { /// Corresponds to the `t` what mask. Returns true if the hook is in a function tail call, false /// otherwise. #[cfg(not(feature = "luau"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub fn is_tail_call(&self) -> bool { unsafe { mlua_assert!( @@ -241,6 +243,7 @@ pub struct DebugStack { /// Determines when a hook function will be called by Lua. #[cfg(not(feature = "luau"))] +#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] #[derive(Clone, Copy, Debug, Default)] pub struct HookTriggers { /// Before a function call. diff --git a/src/lib.rs b/src/lib.rs index ba24e71..0ea54ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ //! [`serde::Deserialize`]: https://docs.serde.rs/serde/de/trait.Deserialize.html // mlua types in rustdoc of other crates get linked to here. -#![doc(html_root_url = "https://docs.rs/mlua/0.8.0-beta.1")] +#![doc(html_root_url = "https://docs.rs/mlua/0.8.0-beta.2")] // Deny warnings inside doc tests / examples. When this isn't present, rustdoc doesn't show *any* // warnings at all. #![doc(test(attr(deny(warnings))))] @@ -124,7 +124,8 @@ pub use crate::value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti #[cfg(not(feature = "luau"))] pub use crate::hook::HookTriggers; -#[cfg(feature = "luau")] +#[cfg(any(feature = "luau", doc))] +#[cfg_attr(docsrs, doc(cfg(feature = "luau")))] pub use crate::chunk::Compiler; #[cfg(feature = "async")] diff --git a/src/lua.rs b/src/lua.rs index a311377..d89dd01 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -810,6 +810,7 @@ impl Lua { /// [`HookTriggers`]: crate::HookTriggers /// [`HookTriggers.every_nth_instruction`]: crate::HookTriggers::every_nth_instruction #[cfg(not(feature = "luau"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub fn set_hook(&self, triggers: HookTriggers, callback: F) -> Result<()> where F: 'static + MaybeSend + FnMut(&Lua, Debug) -> Result<()>, @@ -848,6 +849,7 @@ impl Lua { /// Remove any hook previously set by `set_hook`. This function has no effect if a hook was not /// previously set. #[cfg(not(feature = "luau"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub fn remove_hook(&self) { // If main_state is not available, then sethook wasn't called. let state = match self.main_state { @@ -982,7 +984,7 @@ impl Lua { /// Returns true if the garbage collector is currently running automatically. /// - /// Requires `feature = "lua54/lua53/lua52"` + /// Requires `feature = "lua54/lua53/lua52/luau"` #[cfg(any( feature = "lua54", feature = "lua53", @@ -1046,6 +1048,7 @@ impl Lua { /// /// [lua_doc]: https://www.lua.org/manual/5.4/manual.html#2.5 #[cfg(not(feature = "luau"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub fn gc_set_pause(&self, pause: c_int) -> c_int { let state = self.main_state.unwrap_or(self.state); unsafe { ffi::lua_gc(state, ffi::LUA_GCSETPAUSE, pause) } @@ -1069,6 +1072,7 @@ impl Lua { /// /// [lua_doc]: https://www.lua.org/manual/5.4/manual.html#2.5.1 #[cfg(not(feature = "luau"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub fn gc_inc(&self, pause: c_int, step_multiplier: c_int, step_size: c_int) -> GCMode { let state = self.main_state.unwrap_or(self.state); diff --git a/src/serde/mod.rs b/src/serde/mod.rs index 93c592f..c31e7b1 100644 --- a/src/serde/mod.rs +++ b/src/serde/mod.rs @@ -14,6 +14,7 @@ use crate::util::{assert_stack, check_stack, StackGuard}; use crate::value::Value; /// Trait for serializing/deserializing Lua values using Serde. +#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] pub trait LuaSerdeExt<'lua> { /// A special value (lightuserdata) to encode/decode optional (none) values. /// diff --git a/src/stdlib.rs b/src/stdlib.rs index fd34c43..567fc6c 100644 --- a/src/stdlib.rs +++ b/src/stdlib.rs @@ -8,7 +8,7 @@ pub struct StdLib(u32); impl StdLib { /// [`coroutine`](https://www.lua.org/manual/5.4/manual.html#6.2) library /// - /// Requires `feature = "lua54/lua53/lua52"` + /// Requires `feature = "lua54/lua53/lua52/luau"` #[cfg(any( feature = "lua54", feature = "lua53", @@ -20,6 +20,7 @@ impl StdLib { pub const TABLE: StdLib = StdLib(1 << 1); /// [`io`](https://www.lua.org/manual/5.4/manual.html#6.8) library #[cfg(not(feature = "luau"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub const IO: StdLib = StdLib(1 << 2); /// [`os`](https://www.lua.org/manual/5.4/manual.html#6.9) library pub const OS: StdLib = StdLib(1 << 3); @@ -27,18 +28,19 @@ impl StdLib { pub const STRING: StdLib = StdLib(1 << 4); /// [`utf8`](https://www.lua.org/manual/5.4/manual.html#6.5) library /// - /// Requires `feature = "lua54/lua53"` + /// Requires `feature = "lua54/lua53/luau"` #[cfg(any(feature = "lua54", feature = "lua53", feature = "luau"))] pub const UTF8: StdLib = StdLib(1 << 5); /// [`bit`](https://www.lua.org/manual/5.2/manual.html#6.7) library /// - /// Requires `feature = "lua52/luajit"` + /// Requires `feature = "lua52/luajit/luau"` #[cfg(any(feature = "lua52", feature = "luajit", feature = "luau", doc))] pub const BIT: StdLib = StdLib(1 << 6); /// [`math`](https://www.lua.org/manual/5.4/manual.html#6.7) library pub const MATH: StdLib = StdLib(1 << 7); /// [`package`](https://www.lua.org/manual/5.4/manual.html#6.3) library #[cfg(not(feature = "luau"))] + #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub const PACKAGE: StdLib = StdLib(1 << 8); /// [`jit`](http://luajit.org/ext_jit.html) library /// diff --git a/src/table.rs b/src/table.rs index 4eb4417..4be837c 100644 --- a/src/table.rs +++ b/src/table.rs @@ -352,6 +352,7 @@ impl<'lua> Table<'lua> { /// /// Requires `feature = "luau"` #[cfg(feature = "luau")] + #[cfg_attr(docsrs, doc(cfg(feature = "luau")))] pub fn set_readonly(&self, enabled: bool) { let lua = self.0.lua; unsafe { @@ -363,6 +364,7 @@ impl<'lua> Table<'lua> { /// /// Requires `feature = "luau"` #[cfg(feature = "luau")] + #[cfg_attr(docsrs, doc(cfg(feature = "luau")))] pub fn is_readonly(&self) -> bool { let lua = self.0.lua; unsafe { lua.ref_thread_exec(|refthr| ffi::lua_getreadonly(refthr, self.0.index) != 0) } diff --git a/src/userdata.rs b/src/userdata.rs index 0680779..50c3372 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -865,7 +865,6 @@ impl<'lua> AnyUserData<'lua> { /// /// [`get_user_value`]: #method.get_user_value /// [`set_nth_user_value`]: #method.set_nth_user_value - // #[cfg(not(feature = "luau"))] #[inline] pub fn set_user_value>(&self, v: V) -> Result<()> { self.set_nth_user_value(1, v) @@ -877,7 +876,6 @@ impl<'lua> AnyUserData<'lua> { /// /// [`set_user_value`]: #method.set_user_value /// [`get_nth_user_value`]: #method.get_nth_user_value - // #[cfg(not(feature = "luau"))] #[inline] pub fn get_user_value>(&self) -> Result { self.get_nth_user_value(1) @@ -893,7 +891,6 @@ impl<'lua> AnyUserData<'lua> { /// For other Lua versions this functionality is provided using a wrapping table. /// /// [`get_nth_user_value`]: #method.get_nth_user_value - // #[cfg(not(feature = "luau"))] pub fn set_nth_user_value>(&self, n: usize, v: V) -> Result<()> { if n < 1 || n > u16::MAX as usize { return Err(Error::RuntimeError( @@ -948,7 +945,6 @@ impl<'lua> AnyUserData<'lua> { /// For other Lua versions this functionality is provided using a wrapping table. /// /// [`set_nth_user_value`]: #method.set_nth_user_value - // #[cfg(not(feature = "luau"))] pub fn get_nth_user_value>(&self, n: usize) -> Result { if n < 1 || n > u16::MAX as usize { return Err(Error::RuntimeError( @@ -990,7 +986,6 @@ impl<'lua> AnyUserData<'lua> { /// The value can be retrieved with [`get_named_user_value`]. /// /// [`get_named_user_value`]: #method.get_named_user_value - // #[cfg(not(feature = "luau"))] pub fn set_named_user_value(&self, name: &S, v: V) -> Result<()> where S: AsRef<[u8]> + ?Sized, @@ -1030,7 +1025,6 @@ impl<'lua> AnyUserData<'lua> { /// Returns an associated value by name set by [`set_named_user_value`]. /// /// [`set_named_user_value`]: #method.set_named_user_value - // #[cfg(not(feature = "luau"))] pub fn get_named_user_value(&self, name: &S) -> Result where S: AsRef<[u8]> + ?Sized, diff --git a/src/value.rs b/src/value.rs index 1dfcbbd..9351c1d 100644 --- a/src/value.rs +++ b/src/value.rs @@ -35,7 +35,8 @@ pub enum Value<'lua> { /// A floating point number. Number(Number), /// A Luau vector. - #[cfg(feature = "luau")] + #[cfg(any(feature = "luau", doc))] + #[cfg_attr(docsrs, doc(cfg(feature = "luau")))] Vector(f32, f32, f32), /// An interned string, managed by Lua. ///