From 3d5261640d293c13dbe575c4fdee3eb7746a1da3 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Fri, 6 Jun 2025 23:25:36 +0100 Subject: [PATCH 1/7] Fix doc warnings --- src/state.rs | 4 ++-- src/thread.rs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/state.rs b/src/state.rs index 4be9ba4c..978b1dc9 100644 --- a/src/state.rs +++ b/src/state.rs @@ -377,7 +377,7 @@ impl Lua { /// /// This is similar to setting the [`package.preload[modname]`] field. /// - /// [`package.preload[modname]`]: https://www.lua.org/manual/5.4/manual.html#pdf-package.preload + /// [`package.preload[modname]`]: #[cfg(not(feature = "luau"))] #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub fn preload_module(&self, modname: &str, func: Function) -> Result<()> { @@ -636,7 +636,7 @@ impl Lua { /// Also this can be used to implement continuous execution limits by instructing Luau VM to /// yield by returning [`VmState::Yield`]. /// - /// This is similar to [`Lua::set_hook`] but in more simplified form. + /// This is similar to `Lua::set_hook` but in more simplified form. /// /// # Example /// diff --git a/src/thread.rs b/src/thread.rs index da7962b0..520f0637 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -263,6 +263,8 @@ impl Thread { /// You can have multiple hooks for different threads. /// /// To remove a hook call [`Thread::remove_hook`]. + /// + /// [`Lua::set_hook`]: crate::Lua::set_hook #[cfg(not(feature = "luau"))] #[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))] pub fn set_hook(&self, triggers: HookTriggers, callback: F) -> Result<()> From caeac2e9a3c0492bfad27b85d9f2d6daaa5109f9 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Wed, 11 Jun 2025 22:24:26 +0100 Subject: [PATCH 2/7] Add private app_data container for mlua internal use --- src/chunk.rs | 6 +++--- src/state/extra.rs | 4 +++- src/state/raw.rs | 19 +++++++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/chunk.rs b/src/chunk.rs index 375f15fb..3de61648 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -637,7 +637,7 @@ impl Chunk<'_> { if let Ok(ref source) = self.source { if self.detect_mode() == ChunkMode::Text { let lua = self.lua.lock(); - if let Some(cache) = lua.app_data_ref_unguarded::() { + if let Some(cache) = lua.priv_app_data_ref::() { if let Some(data) = cache.0.get(source.as_ref()) { self.source = Ok(Cow::Owned(data.clone())); self.mode = Some(ChunkMode::Binary); @@ -654,12 +654,12 @@ impl Chunk<'_> { if let Ok(ref binary_source) = self.source { if self.detect_mode() == ChunkMode::Binary { let lua = self.lua.lock(); - if let Some(mut cache) = lua.app_data_mut_unguarded::() { + if let Some(mut cache) = lua.priv_app_data_mut::() { cache.0.insert(text_source, binary_source.to_vec()); } else { let mut cache = ChunksCache(HashMap::new()); cache.0.insert(text_source, binary_source.to_vec()); - let _ = lua.try_set_app_data(cache); + lua.set_priv_app_data(cache); }; } } diff --git a/src/state/extra.rs b/src/state/extra.rs index 12133639..5ff74a33 100644 --- a/src/state/extra.rs +++ b/src/state/extra.rs @@ -44,8 +44,9 @@ pub(crate) struct ExtraData { // When Lua instance dropped, setting `None` would prevent collecting `RegistryKey`s pub(super) registry_unref_list: Arc>>>, - // Container to store arbitrary data (extensions) + // Containers to store arbitrary data (extensions) pub(super) app_data: AppData, + pub(super) app_data_priv: AppData, pub(super) safe: bool, pub(super) libs: StdLib, @@ -159,6 +160,7 @@ impl ExtraData { last_checked_userdata_mt: (ptr::null(), None), registry_unref_list: Arc::new(Mutex::new(Some(Vec::new()))), app_data: AppData::default(), + app_data_priv: AppData::default(), safe: false, libs: StdLib::NONE, skip_memory_check: false, diff --git a/src/state/raw.rs b/src/state/raw.rs index cc4ce1cf..d360877b 100644 --- a/src/state/raw.rs +++ b/src/state/raw.rs @@ -5,7 +5,6 @@ use std::mem; use std::os::raw::{c_char, c_int, c_void}; use std::panic::resume_unwind; use std::ptr::{self, NonNull}; -use std::result::Result as StdResult; use std::sync::Arc; use crate::chunk::ChunkMode; @@ -307,27 +306,27 @@ impl RawLua { res } - /// See [`Lua::try_set_app_data`] + /// Private version of [`Lua::try_set_app_data`] #[inline] - pub(crate) fn try_set_app_data(&self, data: T) -> StdResult, T> { + pub(crate) fn set_priv_app_data(&self, data: T) -> Option { let extra = unsafe { &*self.extra.get() }; - extra.app_data.try_insert(data) + extra.app_data_priv.insert(data) } - /// See [`Lua::app_data_ref`] + /// Private version of [`Lua::app_data_ref`] #[track_caller] #[inline] - pub(crate) fn app_data_ref_unguarded(&self) -> Option> { + pub(crate) fn priv_app_data_ref(&self) -> Option> { let extra = unsafe { &*self.extra.get() }; - extra.app_data.borrow(None) + extra.app_data_priv.borrow(None) } - /// See [`Lua::app_data_mut`] + /// Private version of [`Lua::app_data_mut`] #[track_caller] #[inline] - pub(crate) fn app_data_mut_unguarded(&self) -> Option> { + pub(crate) fn priv_app_data_mut(&self) -> Option> { let extra = unsafe { &*self.extra.get() }; - extra.app_data.borrow_mut(None) + extra.app_data_priv.borrow_mut(None) } /// See [`Lua::create_registry_value`] From a2dc662a9296567f0c6c7b163d22401cdebb08bd Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Wed, 11 Jun 2025 23:55:06 +0100 Subject: [PATCH 3/7] Add RawLua::create_table_from (internal) --- src/state.rs | 27 ++------------------------- src/state/raw.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/state.rs b/src/state.rs index 978b1dc9..dfc73836 100644 --- a/src/state.rs +++ b/src/state.rs @@ -24,9 +24,7 @@ use crate::types::{ ReentrantMutexGuard, RegistryKey, VmState, XRc, XWeak, }; use crate::userdata::{AnyUserData, UserData, UserDataProxy, UserDataRegistry, UserDataStorage}; -use crate::util::{ - assert_stack, check_stack, protect_lua_closure, push_string, push_table, rawset_field, StackGuard, -}; +use crate::util::{assert_stack, check_stack, protect_lua_closure, push_string, rawset_field, StackGuard}; use crate::value::{Nil, Value}; #[cfg(not(feature = "luau"))] @@ -1202,28 +1200,7 @@ impl Lua { K: IntoLua, V: IntoLua, { - let lua = self.lock(); - let state = lua.state(); - unsafe { - let _sg = StackGuard::new(state); - check_stack(state, 6)?; - - let iter = iter.into_iter(); - let lower_bound = iter.size_hint().0; - let protect = !lua.unlikely_memory_error(); - push_table(state, 0, lower_bound, protect)?; - for (k, v) in iter { - lua.push(k)?; - lua.push(v)?; - if protect { - protect_lua!(state, 3, 1, fn(state) ffi::lua_rawset(state, -3))?; - } else { - ffi::lua_rawset(state, -3); - } - } - - Ok(Table(lua.pop_ref())) - } + unsafe { self.lock().create_table_from(iter) } } /// Creates a table from an iterator of values, using `1..` as the keys. diff --git a/src/state/raw.rs b/src/state/raw.rs index d360877b..8efb7146 100644 --- a/src/state/raw.rs +++ b/src/state/raw.rs @@ -537,6 +537,34 @@ impl RawLua { Ok(Table(self.pop_ref())) } + /// See [`Lua::create_table_from`] + pub(crate) unsafe fn create_table_from(&self, iter: I) -> Result + where + I: IntoIterator, + K: IntoLua, + V: IntoLua, + { + let state = self.state(); + let _sg = StackGuard::new(state); + check_stack(state, 6)?; + + let iter = iter.into_iter(); + let lower_bound = iter.size_hint().0; + let protect = !self.unlikely_memory_error(); + push_table(state, 0, lower_bound, protect)?; + for (k, v) in iter { + self.push(k)?; + self.push(v)?; + if protect { + protect_lua!(state, 3, 1, fn(state) ffi::lua_rawset(state, -3))?; + } else { + ffi::lua_rawset(state, -3); + } + } + + Ok(Table(self.pop_ref())) + } + /// See [`Lua::create_sequence_from`] pub(crate) unsafe fn create_sequence_from(&self, iter: I) -> Result
where From f00208373e10305470234d9ef5be117fcb4a4e04 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Thu, 12 Jun 2025 00:17:29 +0100 Subject: [PATCH 4/7] Bump lua-src --- mlua-sys/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlua-sys/Cargo.toml b/mlua-sys/Cargo.toml index 0ce088da..34e785d3 100644 --- a/mlua-sys/Cargo.toml +++ b/mlua-sys/Cargo.toml @@ -38,7 +38,7 @@ module = [] cc = "1.0" cfg-if = "1.0" pkg-config = "0.3.17" -lua-src = { version = ">= 548.0.0, < 548.1.0", optional = true } +lua-src = { version = ">= 548.1.0, < 548.2.0", optional = true } luajit-src = { version = ">= 210.6.0, < 210.7.0", optional = true } luau0-src = { version = "0.15.0", optional = true } From 2fbbbe4238eb9c0a12e5c052de2c2f5cef548ebe Mon Sep 17 00:00:00 2001 From: Ron Tseytlin <40004112+steveRoll-git@users.noreply.github.com> Date: Thu, 12 Jun 2025 14:57:11 +0300 Subject: [PATCH 5/7] Fix minor grammar mistakes in README.md (#591) --- README.md | 70 +++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index a660a19a..c0c3e26b 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,12 @@ > > See v0.10 [release notes](https://github.com/mlua-rs/mlua/blob/main/docs/release_notes/v0.10.md). -`mlua` is bindings to [Lua](https://www.lua.org) programming language for Rust with a goal to provide -_safe_ (as far as it's possible), high level, easy to use, practical and flexible API. +`mlua` is a set of bindings to the [Lua](https://www.lua.org) programming language for Rust with a goal to provide a +_safe_ (as much as possible), high level, easy to use, practical and flexible API. -Started as `rlua` fork, `mlua` supports Lua 5.4, 5.3, 5.2, 5.1 (including LuaJIT) and [Luau] and allows to write native Lua modules in Rust as well as use Lua in a standalone mode. +Started as an `rlua` fork, `mlua` supports Lua 5.4, 5.3, 5.2, 5.1 (including LuaJIT) and [Luau] and allows writing native Lua modules in Rust as well as using Lua in a standalone mode. -`mlua` tested on Windows/macOS/Linux including module mode in [GitHub Actions] on `x86_64` platform and cross-compilation to `aarch64` (other targets are also supported). +`mlua` is tested on Windows/macOS/Linux including module mode in [GitHub Actions] on `x86_64` platforms and cross-compilation to `aarch64` (other targets are also supported). WebAssembly (WASM) is supported through `wasm32-unknown-emscripten` target for all Lua/Luau versions excluding JIT. @@ -39,7 +39,7 @@ WebAssembly (WASM) is supported through `wasm32-unknown-emscripten` target for a ### Feature flags -`mlua` uses feature flags to reduce the amount of dependencies, compiled code and allow to choose only required set of features. +`mlua` uses feature flags to reduce the amount of dependencies and compiled code, and allow to choose only required set of features. Below is a list of the available feature flags. By default `mlua` does not enable any features. * `lua54`: enable Lua [5.4] support @@ -51,12 +51,12 @@ Below is a list of the available feature flags. By default `mlua` does not enabl * `luau`: enable [Luau] support (auto vendored mode) * `luau-jit`: enable [Luau] support with JIT backend. * `luau-vector4`: enable [Luau] support with 4-dimensional vector. -* `vendored`: build static Lua(JIT) library from sources during `mlua` compilation using [lua-src] or [luajit-src] crates +* `vendored`: build static Lua(JIT) libraries from sources during `mlua` compilation using [lua-src] or [luajit-src] * `module`: enable module mode (building loadable `cdylib` library for Lua) * `async`: enable async/await support (any executor can be used, eg. [tokio] or [async-std]) * `send`: make `mlua::Lua: Send + Sync` (adds [`Send`] requirement to `mlua::Function` and `mlua::UserData`) * `error-send`: make `mlua:Error: Send + Sync` -* `serialize`: add serialization and deserialization support to `mlua` types using [serde] framework +* `serialize`: add serialization and deserialization support to `mlua` types using [serde] * `macros`: enable procedural macros (such as `chunk!`) * `anyhow`: enable `anyhow::Error` conversion into Lua * `userdata-wrappers`: opt into `impl UserData` for `Rc`/`Arc`/`Rc>`/`Arc>` where `T: UserData` @@ -78,7 +78,7 @@ Below is a list of the available feature flags. By default `mlua` does not enabl `mlua` supports async/await for all Lua versions including Luau. -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 `feature = "async"` in `Cargo.toml`. +This works using Lua [coroutines](https://www.lua.org/manual/5.3/manual.html#2.6) and requires running [Thread](https://docs.rs/mlua/latest/mlua/struct.Thread.html) along with enabling `feature = "async"` in `Cargo.toml`. **Examples**: - [HTTP Client](examples/async_http_client.rs) @@ -102,7 +102,7 @@ curl -v http://localhost:3000 ### Serialization (serde) support -With `serialize` feature flag enabled, `mlua` allows you to serialize/deserialize any type that implements [`serde::Serialize`] and [`serde::Deserialize`] into/from [`mlua::Value`]. In addition `mlua` provides [`serde::Serialize`] trait implementation for it (including `UserData` support). +With the `serialize` feature flag enabled, `mlua` allows you to serialize/deserialize any type that implements [`serde::Serialize`] and [`serde::Deserialize`] into/from [`mlua::Value`]. In addition, `mlua` provides the [`serde::Serialize`] trait implementation for it (including `UserData` support). [Example](examples/serialize.rs) @@ -114,24 +114,24 @@ With `serialize` feature flag enabled, `mlua` allows you to serialize/deserializ You have to enable one of the features: `lua54`, `lua53`, `lua52`, `lua51`, `luajit(52)` or `luau`, according to the chosen Lua version. -By default `mlua` uses `pkg-config` tool to find lua includes and libraries for the chosen Lua version. -In most cases it works as desired, although sometimes could be more preferable to use a custom lua library. -To achieve this, mlua supports `LUA_LIB`, `LUA_LIB_NAME` and `LUA_LINK` environment variables. +By default `mlua` uses `pkg-config` to find Lua includes and libraries for the chosen Lua version. +In most cases it works as desired, although sometimes it may be preferable to use a custom Lua library. +To achieve this, mlua supports the `LUA_LIB`, `LUA_LIB_NAME` and `LUA_LINK` environment variables. `LUA_LINK` is optional and may be `dylib` (a dynamic library) or `static` (a static library, `.a` archive). -An example how to use them: +An example of how to use them: ``` sh my_project $ LUA_LIB=$HOME/tmp/lua-5.2.4/src LUA_LIB_NAME=lua LUA_LINK=static cargo build ``` -`mlua` also supports vendored lua/luajit using the auxiliary crates [lua-src](https://crates.io/crates/lua-src) and +`mlua` also supports vendored Lua/LuaJIT using the auxiliary crates [lua-src](https://crates.io/crates/lua-src) and [luajit-src](https://crates.io/crates/luajit-src). -Just enable the `vendored` feature and cargo will automatically build and link specified lua/luajit version. This is the easiest way to get started with `mlua`. +Just enable the `vendored` feature and cargo will automatically build and link the specified Lua/LuaJIT version. This is the easiest way to get started with `mlua`. ### Standalone mode -In a standalone mode `mlua` allows to add to your application scripting support with a gently configured Lua runtime to ensure safety and soundness. +In standalone mode, `mlua` allows adding scripting support to your application with a gently configured Lua runtime to ensure safety and soundness. -Add to `Cargo.toml` : +Add to `Cargo.toml`: ``` toml [dependencies] @@ -159,11 +159,11 @@ fn main() -> LuaResult<()> { ``` ### Module mode -In a module mode `mlua` allows to create a compiled Lua module that can be loaded from Lua code using [`require`](https://www.lua.org/manual/5.4/manual.html#pdf-require). In this case `mlua` uses an external Lua runtime which could lead to potential unsafety due to unpredictability of the Lua environment and usage of libraries such as [`debug`](https://www.lua.org/manual/5.4/manual.html#6.10). +In module mode, `mlua` allows creating a compiled Lua module that can be loaded from Lua code using [`require`](https://www.lua.org/manual/5.4/manual.html#pdf-require). In this case `mlua` uses an external Lua runtime which could lead to potential unsafety due to the unpredictability of the Lua environment and usage of libraries such as [`debug`](https://www.lua.org/manual/5.4/manual.html#6.10). [Example](examples/module) -Add to `Cargo.toml` : +Add to `Cargo.toml`: ``` toml [lib] @@ -173,7 +173,7 @@ crate-type = ["cdylib"] mlua = { version = "0.10", features = ["lua54", "module"] } ``` -`lib.rs` : +`lib.rs`: ``` rust use mlua::prelude::*; @@ -216,14 +216,14 @@ rustflags = [ ``` On Linux you can build modules normally with `cargo build --release`. -On Windows the target module will be linked with `lua5x.dll` library (depending on your feature flags). +On Windows the target module will be linked with the `lua5x.dll` library (depending on your feature flags). Your main application should provide this library. -Module builds don't require Lua lib or headers to be installed on the system. +Module builds don't require Lua binaries or headers to be installed on the system. ### Publishing to luarocks.org -There is a LuaRocks build backend for mlua modules [`luarocks-build-rust-mlua`]. +There is a LuaRocks build backend for mlua modules: [`luarocks-build-rust-mlua`]. Modules written in Rust and published to luarocks: - [`decasify`](https://github.com/alerque/decasify) @@ -236,10 +236,10 @@ Modules written in Rust and published to luarocks: ## Safety -One of the `mlua` goals is to provide *safe* API between Rust and Lua. -Every place where the Lua C API may trigger an error longjmp in any way is protected by `lua_pcall`, -and the user of the library is protected from directly interacting with unsafe things like the Lua stack, -and there is overhead associated with this safety. +One of `mlua`'s goals is to provide a *safe* API between Rust and Lua. +Every place where the Lua C API may trigger an error longjmp is protected by `lua_pcall`, +and the user of the library is protected from directly interacting with unsafe things like the Lua stack. +There is overhead associated with this safety. Unfortunately, `mlua` does not provide absolute safety even without using `unsafe` . This library contains a huge amount of unsafe code. There are almost certainly bugs still lurking in this library! @@ -247,8 +247,8 @@ It is surprisingly, fiendishly difficult to use the Lua C API without the potent ## Panic handling -`mlua` wraps panics that are generated inside Rust callbacks in a regular Lua error. Panics could be -resumed then by returning or propagating the Lua error to Rust code. +`mlua` wraps panics that are generated inside Rust callbacks in a regular Lua error. Panics can then be +resumed by returning or propagating the Lua error to Rust code. For example: ``` rust @@ -267,12 +267,12 @@ let _ = lua.load(r#" unreachable!() ``` -Optionally `mlua` can disable Rust panics catching in Lua via `pcall`/`xpcall` and automatically resume +Optionally, `mlua` can disable Rust panic catching in Lua via `pcall`/`xpcall` and automatically resume them across the Lua API boundary. This is controlled via `LuaOptions` and done by wrapping the Lua `pcall`/`xpcall` -functions on a way to prevent catching errors that are wrapped Rust panics. +functions to prevent catching errors that are wrapped Rust panics. `mlua` should also be panic safe in another way as well, which is that any `Lua` instances or handles -remains usable after a user generated panic, and such panics should not break internal invariants or +remain usable after a user generated panic, and such panics should not break internal invariants or leak Lua stack space. This is mostly important to safely use `mlua` types in Drop impls, as you should not be using panics for general error handling. @@ -289,12 +289,12 @@ If you encounter them, a bug report would be very welcome: ## Sandboxing -Please check the [Luau Sandboxing] page if you are interested in running untrusted Lua scripts in controlled environment. +Please check the [Luau Sandboxing] page if you are interested in running untrusted Lua scripts in a controlled environment. -`mlua` provides `Lua::sandbox` method for enabling sandbox mode (Luau only). +`mlua` provides the `Lua::sandbox` method for enabling sandbox mode (Luau only). [Luau Sandboxing]: https://luau.org/sandbox ## License -This project is licensed under the [MIT license](LICENSE) +This project is licensed under the [MIT license](LICENSE). From 7bc72be7d39fa9f1ec5155049057771d684cab10 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Thu, 12 Jun 2025 13:35:22 +0100 Subject: [PATCH 6/7] Use `serde` feature flag instead of `serialize`. The old one is still supported. --- .github/workflows/main.yml | 26 +++++++++++++------------- Cargo.toml | 15 +++++++++------ README.md | 6 +++--- examples/{serialize.rs => serde.rs} | 0 src/buffer.rs | 4 ++-- src/error.rs | 16 ++++++++-------- src/lib.rs | 8 ++++---- src/prelude.rs | 2 +- src/serde/mod.rs | 2 +- src/state.rs | 10 +++++----- src/state/raw.rs | 2 +- src/string.rs | 4 ++-- src/table.rs | 12 ++++++------ src/userdata.rs | 10 +++++----- src/userdata/cell.rs | 24 ++++++++++++------------ src/value.rs | 16 ++++++++-------- src/vector.rs | 4 ++-- tarpaulin.toml | 14 +++++++------- tests/serde.rs | 2 +- tests/userdata.rs | 8 ++++---- 20 files changed, 94 insertions(+), 91 deletions(-) rename examples/{serialize.rs => serde.rs} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a0be1e5f..8d8e51f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,8 +27,8 @@ jobs: - name: Build ${{ matrix.lua }} vendored run: | cargo build --features "${{ matrix.lua }},vendored" - cargo build --features "${{ matrix.lua }},vendored,async,serialize,macros,anyhow,userdata-wrappers" - cargo build --features "${{ matrix.lua }},vendored,async,serialize,macros,anyhow,userdata-wrappers,send" + cargo build --features "${{ matrix.lua }},vendored,async,serde,macros,anyhow,userdata-wrappers" + cargo build --features "${{ matrix.lua }},vendored,async,serde,macros,anyhow,userdata-wrappers,send" shell: bash - name: Build ${{ matrix.lua }} pkg-config if: ${{ matrix.os == 'ubuntu-latest' }} @@ -51,7 +51,7 @@ jobs: toolchain: stable target: aarch64-apple-darwin - name: Cross-compile - run: cargo build --target aarch64-apple-darwin --features "${{ matrix.lua }},vendored,async,send,serialize,macros,anyhow,userdata-wrappers" + run: cargo build --target aarch64-apple-darwin --features "${{ matrix.lua }},vendored,async,send,serde,macros,anyhow,userdata-wrappers" build_aarch64_cross_ubuntu: name: Cross-compile to aarch64-unknown-linux-gnu @@ -72,7 +72,7 @@ jobs: sudo apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross shell: bash - name: Cross-compile - run: cargo build --target aarch64-unknown-linux-gnu --features "${{ matrix.lua }},vendored,async,send,serialize,macros,anyhow,userdata-wrappers" + run: cargo build --target aarch64-unknown-linux-gnu --features "${{ matrix.lua }},vendored,async,send,serde,macros,anyhow,userdata-wrappers" shell: bash build_armv7_cross_ubuntu: @@ -94,7 +94,7 @@ jobs: sudo apt-get install -y --no-install-recommends gcc-arm-linux-gnueabihf libc-dev-armhf-cross shell: bash - name: Cross-compile - run: cargo build --target armv7-unknown-linux-gnueabihf --features "${{ matrix.lua }},vendored,async,send,serialize,macros,anyhow,userdata-wrappers" + run: cargo build --target armv7-unknown-linux-gnueabihf --features "${{ matrix.lua }},vendored,async,send,serde,macros,anyhow,userdata-wrappers" shell: bash test: @@ -123,14 +123,14 @@ jobs: - name: Run ${{ matrix.lua }} tests run: | cargo test --features "${{ matrix.lua }},vendored" - cargo test --features "${{ matrix.lua }},vendored,async,serialize,macros,anyhow,userdata-wrappers" - cargo test --features "${{ matrix.lua }},vendored,async,serialize,macros,anyhow,userdata-wrappers,send" + cargo test --features "${{ matrix.lua }},vendored,async,serde,macros,anyhow,userdata-wrappers" + cargo test --features "${{ matrix.lua }},vendored,async,serde,macros,anyhow,userdata-wrappers,send" shell: bash - name: Run compile tests (macos lua54) if: ${{ matrix.os == 'macos-latest' && matrix.lua == 'lua54' }} run: | TRYBUILD=overwrite cargo test --features "${{ matrix.lua }},vendored" --tests -- --ignored - TRYBUILD=overwrite cargo test --features "${{ matrix.lua }},vendored,async,send,serialize,macros" --tests -- --ignored + TRYBUILD=overwrite cargo test --features "${{ matrix.lua }},vendored,async,send,serde,macros" --tests -- --ignored shell: bash test_with_sanitizer: @@ -154,8 +154,8 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Run ${{ matrix.lua }} tests with address sanitizer run: | - cargo test --tests --features "${{ matrix.lua }},vendored,async,serialize,macros,anyhow" --target x86_64-unknown-linux-gnu -- --skip test_too_many_recursions - cargo test --tests --features "${{ matrix.lua }},vendored,async,serialize,macros,anyhow,userdata-wrappers,send" --target x86_64-unknown-linux-gnu -- --skip test_too_many_recursions + cargo test --tests --features "${{ matrix.lua }},vendored,async,serde,macros,anyhow" --target x86_64-unknown-linux-gnu -- --skip test_too_many_recursions + cargo test --tests --features "${{ matrix.lua }},vendored,async,serde,macros,anyhow,userdata-wrappers,send" --target x86_64-unknown-linux-gnu -- --skip test_too_many_recursions shell: bash env: RUSTFLAGS: -Z sanitizer=address @@ -181,7 +181,7 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Run ${{ matrix.lua }} tests with forced memory limit run: | - cargo test --tests --features "${{ matrix.lua }},vendored,async,send,serialize,macros,anyhow,userdata-wrappers" + cargo test --tests --features "${{ matrix.lua }},vendored,async,send,serde,macros,anyhow,userdata-wrappers" shell: bash env: RUSTFLAGS: --cfg=force_memory_limit @@ -254,7 +254,7 @@ jobs: - name: Run ${{ matrix.lua }} tests run: | cargo test --tests --features "${{ matrix.lua }},vendored" - cargo test --tests --features "${{ matrix.lua }},vendored,async,serialize,macros,anyhow,userdata-wrappers" + cargo test --tests --features "${{ matrix.lua }},vendored,async,serde,macros,anyhow,userdata-wrappers" rustfmt: name: Rustfmt @@ -281,4 +281,4 @@ jobs: - uses: giraffate/clippy-action@v1 with: reporter: 'github-pr-review' - clippy_flags: --features "${{ matrix.lua }},vendored,async,send,serialize,macros,anyhow,userdata-wrappers" + clippy_flags: --features "${{ matrix.lua }},vendored,async,send,serde,macros,anyhow,userdata-wrappers" diff --git a/Cargo.toml b/Cargo.toml index 65ac1ba8..1cc3ab7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ with async/await features and support of writing native Lua modules in Rust. """ [package.metadata.docs.rs] -features = ["lua54", "vendored", "async", "send", "serialize", "macros"] +features = ["lua54", "vendored", "async", "send", "serde", "macros"] rustdoc-args = ["--cfg", "docsrs"] [workspace] @@ -40,11 +40,14 @@ module = ["mlua_derive", "ffi/module"] async = ["dep:futures-util"] send = ["error-send"] error-send = [] -serialize = ["dep:serde", "dep:erased-serde", "dep:serde-value", "bstr/serde"] +serde = ["dep:serde", "dep:erased-serde", "dep:serde-value", "bstr/serde"] macros = ["mlua_derive/macros"] anyhow = ["dep:anyhow", "error-send"] userdata-wrappers = ["parking_lot/send_guard"] +# deprecated features +serialize = ["serde"] + [dependencies] mlua_derive = { version = "=0.11.0-beta.2", optional = true, path = "mlua_derive" } bstr = { version = "1.0", features = ["std"], default-features = false } @@ -90,7 +93,7 @@ required-features = ["async"] [[bench]] name = "serde" harness = false -required-features = ["serialize"] +required-features = ["serde"] [[example]] name = "async_http_client" @@ -98,7 +101,7 @@ required-features = ["async", "macros"] [[example]] name = "async_http_reqwest" -required-features = ["async", "serialize", "macros"] +required-features = ["async", "serde", "macros"] [[example]] name = "async_http_server" @@ -113,8 +116,8 @@ name = "guided_tour" required-features = ["macros"] [[example]] -name = "serialize" -required-features = ["serialize"] +name = "serde" +required-features = ["serde"] [[example]] name = "userdata" diff --git a/README.md b/README.md index c0c3e26b..ec41d3d4 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Below is a list of the available feature flags. By default `mlua` does not enabl * `async`: enable async/await support (any executor can be used, eg. [tokio] or [async-std]) * `send`: make `mlua::Lua: Send + Sync` (adds [`Send`] requirement to `mlua::Function` and `mlua::UserData`) * `error-send`: make `mlua:Error: Send + Sync` -* `serialize`: add serialization and deserialization support to `mlua` types using [serde] +* `serde`: add serialization and deserialization support to `mlua` types using [serde] * `macros`: enable procedural macros (such as `chunk!`) * `anyhow`: enable `anyhow::Error` conversion into Lua * `userdata-wrappers`: opt into `impl UserData` for `Rc`/`Arc`/`Rc>`/`Arc>` where `T: UserData` @@ -93,7 +93,7 @@ This works using Lua [coroutines](https://www.lua.org/manual/5.3/manual.html#2.6 cargo run --example async_http_client --features=lua54,async,macros # async http client (reqwest) -cargo run --example async_http_reqwest --features=lua54,async,macros,serialize +cargo run --example async_http_reqwest --features=lua54,async,macros,serde # async http server cargo run --example async_http_server --features=lua54,async,macros,send @@ -102,7 +102,7 @@ curl -v http://localhost:3000 ### Serialization (serde) support -With the `serialize` feature flag enabled, `mlua` allows you to serialize/deserialize any type that implements [`serde::Serialize`] and [`serde::Deserialize`] into/from [`mlua::Value`]. In addition, `mlua` provides the [`serde::Serialize`] trait implementation for it (including `UserData` support). +With the `serde` feature flag enabled, `mlua` allows you to serialize/deserialize any type that implements [`serde::Serialize`] and [`serde::Deserialize`] into/from [`mlua::Value`]. In addition, `mlua` provides the [`serde::Serialize`] trait implementation for it (including `UserData` support). [Example](examples/serialize.rs) diff --git a/examples/serialize.rs b/examples/serde.rs similarity index 100% rename from examples/serialize.rs rename to examples/serde.rs diff --git a/src/buffer.rs b/src/buffer.rs index 42b20088..0ee163ff 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1,4 +1,4 @@ -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] use serde::ser::{Serialize, Serializer}; use crate::types::ValueRef; @@ -73,7 +73,7 @@ impl Buffer { } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl Serialize for Buffer { fn serialize(&self, serializer: S) -> std::result::Result { serializer.serialize_bytes(unsafe { self.as_slice() }) diff --git a/src/error.rs b/src/error.rs index 1f243967..c20a39ef 100644 --- a/src/error.rs +++ b/src/error.rs @@ -183,12 +183,12 @@ pub enum Error { /// and returned again. PreviouslyResumedPanic, /// Serialization error. - #[cfg(feature = "serialize")] - #[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] + #[cfg(feature = "serde")] + #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] SerializeError(StdString), /// Deserialization error. - #[cfg(feature = "serialize")] - #[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] + #[cfg(feature = "serde")] + #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] DeserializeError(StdString), /// A custom error. /// @@ -309,11 +309,11 @@ impl fmt::Display for Error { Error::PreviouslyResumedPanic => { write!(fmt, "previously resumed panic returned again") } - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] Error::SerializeError(err) => { write!(fmt, "serialize error: {err}") }, - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] Error::DeserializeError(err) => { write!(fmt, "deserialize error: {err}") }, @@ -494,14 +494,14 @@ impl From for Error { } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl serde::ser::Error for Error { fn custom(msg: T) -> Self { Self::SerializeError(msg.to_string()) } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl serde::de::Error for Error { fn custom(msg: T) -> Self { Self::DeserializeError(msg.to_string()) diff --git a/src/lib.rs b/src/lib.rs index dc15737b..e1589ce6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,7 +35,7 @@ //! The [`Value`] enum and other types implement [`serde::Serialize`] trait to support serializing //! Lua values into Rust values. //! -//! Requires `feature = "serialize"`. +//! Requires `feature = "serde"`. //! //! # Async/await support //! @@ -140,12 +140,12 @@ pub use crate::{ #[cfg_attr(docsrs, doc(cfg(feature = "async")))] pub use crate::{thread::AsyncThread, traits::LuaNativeAsyncFn}; -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] #[doc(inline)] pub use crate::serde::{de::Options as DeserializeOptions, ser::Options as SerializeOptions, LuaSerdeExt}; -#[cfg(feature = "serialize")] -#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] +#[cfg(feature = "serde")] +#[cfg_attr(docsrs, doc(cfg(feature = "serde")))] pub mod serde; #[cfg(feature = "mlua_derive")] diff --git a/src/prelude.rs b/src/prelude.rs index eeeaea26..a3a03201 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -32,7 +32,7 @@ pub use crate::{ #[doc(no_inline)] pub use crate::{AsyncThread as LuaAsyncThread, LuaNativeAsyncFn}; -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] #[doc(no_inline)] pub use crate::{ DeserializeOptions as LuaDeserializeOptions, LuaSerdeExt, SerializeOptions as LuaSerializeOptions, diff --git a/src/serde/mod.rs b/src/serde/mod.rs index f4752145..1b85a763 100644 --- a/src/serde/mod.rs +++ b/src/serde/mod.rs @@ -13,7 +13,7 @@ use crate::util::check_stack; use crate::value::Value; /// Trait for serializing/deserializing Lua values using Serde. -#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] +#[cfg_attr(docsrs, doc(cfg(feature = "serde")))] pub trait LuaSerdeExt: Sealed { /// A special value (lightuserdata) to encode/decode optional (none) values. /// diff --git a/src/state.rs b/src/state.rs index dfc73836..dbe4c2b2 100644 --- a/src/state.rs +++ b/src/state.rs @@ -39,7 +39,7 @@ use { std::future::{self, Future}, }; -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] use serde::Serialize; pub(crate) use extra::ExtraData; @@ -1367,8 +1367,8 @@ impl Lua { } /// Creates a Lua userdata object from a custom serializable userdata type. - #[cfg(feature = "serialize")] - #[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] + #[cfg(feature = "serde")] + #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] #[inline] pub fn create_ser_userdata(&self, data: T) -> Result where @@ -1395,8 +1395,8 @@ impl Lua { /// Creates a Lua userdata object from a custom serializable Rust type. /// /// See [`Lua::create_any_userdata`] for more details. - #[cfg(feature = "serialize")] - #[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] + #[cfg(feature = "serde")] + #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] #[inline] pub fn create_ser_any_userdata(&self, data: T) -> Result where diff --git a/src/state/raw.rs b/src/state/raw.rs index 8efb7146..b7de97f2 100644 --- a/src/state/raw.rs +++ b/src/state/raw.rs @@ -208,7 +208,7 @@ impl RawLua { } // Init serde metatables - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] crate::serde::init_metatables(state)?; Ok::<_, Error>(()) diff --git a/src/string.rs b/src/string.rs index 9c86102b..6304d484 100644 --- a/src/string.rs +++ b/src/string.rs @@ -11,7 +11,7 @@ use crate::traits::IntoLua; use crate::types::{LuaType, ValueRef}; use crate::value::Value; -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] use { serde::ser::{Serialize, Serializer}, std::result::Result as StdResult, @@ -211,7 +211,7 @@ impl Hash for String { } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl Serialize for String { fn serialize(&self, serializer: S) -> StdResult where diff --git a/src/table.rs b/src/table.rs index 92228683..4b62705d 100644 --- a/src/table.rs +++ b/src/table.rs @@ -15,7 +15,7 @@ use crate::value::{Nil, Value}; #[cfg(feature = "async")] use futures_util::future::{self, Either, Future}; -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] use { rustc_hash::FxHashSet, serde::ser::{Serialize, SerializeMap, SerializeSeq, Serializer}, @@ -735,7 +735,7 @@ impl Table { Ok(()) } - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] pub(crate) fn is_array(&self) -> bool { let lua = self.0.lua.lock(); let state = lua.state(); @@ -954,14 +954,14 @@ impl ObjectLike for Table { } /// A wrapped [`Table`] with customized serialization behavior. -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] pub(crate) struct SerializableTable<'a> { table: &'a Table, options: crate::serde::de::Options, visited: Rc>>, } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl Serialize for Table { #[inline] fn serialize(&self, serializer: S) -> StdResult { @@ -969,7 +969,7 @@ impl Serialize for Table { } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl<'a> SerializableTable<'a> { #[inline] pub(crate) fn new( @@ -985,7 +985,7 @@ impl<'a> SerializableTable<'a> { } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl Serialize for SerializableTable<'_> { fn serialize(&self, serializer: S) -> StdResult where diff --git a/src/userdata.rs b/src/userdata.rs index 9bdfbd81..a568485d 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -18,7 +18,7 @@ use crate::value::Value; #[cfg(feature = "async")] use std::future::Future; -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] use { serde::ser::{self, Serialize, Serializer}, std::result::Result as StdResult, @@ -957,7 +957,7 @@ impl AnyUserData { /// Returns `true` if this [`AnyUserData`] is serializable (e.g. was created using /// [`Lua::create_ser_userdata`]). - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] pub(crate) fn is_serializable(&self) -> bool { let lua = self.0.lua.lock(); let is_serializable = || unsafe { @@ -1041,7 +1041,7 @@ where } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl Serialize for AnyUserData { fn serialize(&self, serializer: S) -> StdResult where @@ -1072,8 +1072,8 @@ impl AnyUserData { /// [`IntoLua`] trait. /// /// This function uses [`Lua::create_ser_any_userdata`] under the hood. - #[cfg(feature = "serialize")] - #[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] + #[cfg(feature = "serde")] + #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] pub fn wrap_ser(data: T) -> impl IntoLua { WrappedUserdata(move |lua| lua.create_ser_any_userdata(data)) } diff --git a/src/userdata/cell.rs b/src/userdata/cell.rs index 538e33d7..f70399cd 100644 --- a/src/userdata/cell.rs +++ b/src/userdata/cell.rs @@ -1,6 +1,6 @@ use std::cell::{RefCell, UnsafeCell}; -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] use serde::ser::{Serialize, Serializer}; use crate::error::{Error, Result}; @@ -9,10 +9,10 @@ use crate::types::XRc; use super::lock::{RawLock, UserDataLock}; use super::r#ref::{UserDataRef, UserDataRefMut}; -#[cfg(all(feature = "serialize", not(feature = "send")))] +#[cfg(all(feature = "serde", not(feature = "send")))] type DynSerialize = dyn erased_serde::Serialize; -#[cfg(all(feature = "serialize", feature = "send"))] +#[cfg(all(feature = "serde", feature = "send"))] type DynSerialize = dyn erased_serde::Serialize + Send; pub(crate) enum UserDataStorage { @@ -24,7 +24,7 @@ pub(crate) enum UserDataStorage { // It's stored inside a Lua VM and protected by the outer `ReentrantMutex`. pub(crate) enum UserDataVariant { Default(XRc>), - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] Serializable(XRc>>, bool), // bool is `is_sync` } @@ -33,7 +33,7 @@ impl Clone for UserDataVariant { fn clone(&self) -> Self { match self { Self::Default(inner) => Self::Default(XRc::clone(inner)), - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] Self::Serializable(inner, is_sync) => Self::Serializable(XRc::clone(inner), *is_sync), } } @@ -79,7 +79,7 @@ impl UserDataVariant { } Ok(match self { Self::Default(inner) => XRc::into_inner(inner).unwrap().value.into_inner(), - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] Self::Serializable(inner, _) => unsafe { let raw = Box::into_raw(XRc::into_inner(inner).unwrap().value.into_inner()); *Box::from_raw(raw as *mut T) @@ -91,7 +91,7 @@ impl UserDataVariant { fn strong_count(&self) -> usize { match self { Self::Default(inner) => XRc::strong_count(inner), - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] Self::Serializable(inner, _) => XRc::strong_count(inner), } } @@ -100,7 +100,7 @@ impl UserDataVariant { pub(super) fn raw_lock(&self) -> &RawLock { match self { Self::Default(inner) => &inner.raw_lock, - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] Self::Serializable(inner, _) => &inner.raw_lock, } } @@ -109,13 +109,13 @@ impl UserDataVariant { pub(super) fn as_ptr(&self) -> *mut T { match self { Self::Default(inner) => inner.value.get(), - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] Self::Serializable(inner, _) => unsafe { &mut **(inner.value.get() as *mut Box) }, } } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl Serialize for UserDataStorage<()> { fn serialize(&self, serializer: S) -> std::result::Result { match self { @@ -197,7 +197,7 @@ impl UserDataStorage { Self::Scoped(ScopedUserDataVariant::RefMut(RefCell::new(data))) } - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] #[inline(always)] pub(crate) fn new_ser(data: T) -> Self where @@ -209,7 +209,7 @@ impl UserDataStorage { Self::Owned(variant) } - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] #[inline(always)] pub(crate) fn is_serializable(&self) -> bool { matches!(self, Self::Owned(UserDataVariant::Serializable(..))) diff --git a/src/value.rs b/src/value.rs index 119f147e..cfc13251 100644 --- a/src/value.rs +++ b/src/value.rs @@ -15,7 +15,7 @@ use crate::types::{Integer, LightUserData, Number, ValueRef}; use crate::userdata::AnyUserData; use crate::util::{check_stack, StackGuard}; -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] use { crate::table::SerializableTable, rustc_hash::FxHashSet, @@ -481,8 +481,8 @@ impl Value { /// Wrap reference to this Value into [`SerializableValue`]. /// /// This allows customizing serialization behavior using serde. - #[cfg(feature = "serialize")] - #[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] + #[cfg(feature = "serde")] + #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] #[doc(hidden)] pub fn to_serializable(&self) -> SerializableValue { SerializableValue::new(self, Default::default(), None) @@ -630,8 +630,8 @@ impl PartialEq for Value { } /// A wrapped [`Value`] with customized serialization behavior. -#[cfg(feature = "serialize")] -#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))] +#[cfg(feature = "serde")] +#[cfg_attr(docsrs, doc(cfg(feature = "serde")))] pub struct SerializableValue<'a> { value: &'a Value, options: crate::serde::de::Options, @@ -639,7 +639,7 @@ pub struct SerializableValue<'a> { visited: Option>>>, } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl Serialize for Value { #[inline] fn serialize(&self, serializer: S) -> StdResult { @@ -647,7 +647,7 @@ impl Serialize for Value { } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl<'a> SerializableValue<'a> { #[inline] pub(crate) fn new( @@ -711,7 +711,7 @@ impl<'a> SerializableValue<'a> { } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl Serialize for SerializableValue<'_> { fn serialize(&self, serializer: S) -> StdResult where diff --git a/src/vector.rs b/src/vector.rs index 57a5a96d..462cafac 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -1,6 +1,6 @@ use std::fmt; -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] use serde::ser::{Serialize, SerializeTupleStruct, Serializer}; /// A Luau vector type. @@ -66,7 +66,7 @@ impl Vector { } } -#[cfg(feature = "serialize")] +#[cfg(feature = "serde")] impl Serialize for Vector { fn serialize(&self, serializer: S) -> std::result::Result { let mut ts = serializer.serialize_tuple_struct("Vector", Self::SIZE)?; diff --git a/tarpaulin.toml b/tarpaulin.toml index 71c73a35..48bd33f3 100644 --- a/tarpaulin.toml +++ b/tarpaulin.toml @@ -1,23 +1,23 @@ [lua54] -features = "lua54,vendored,async,send,serialize,macros,anyhow,userdata-wrappers" +features = "lua54,vendored,async,send,serde,macros,anyhow,userdata-wrappers" [lua54_non_send] -features = "lua54,vendored,async,serialize,macros,anyhow,userdata-wrappers" +features = "lua54,vendored,async,serde,macros,anyhow,userdata-wrappers" [lua54_with_memory_limit] -features = "lua54,vendored,async,send,serialize,macros,anyhow,userdata-wrappers" +features = "lua54,vendored,async,send,serde,macros,anyhow,userdata-wrappers" rustflags = "--cfg force_memory_limit" [lua51] -features = "lua51,vendored,async,send,serialize,macros" +features = "lua51,vendored,async,send,serde,macros" [lua51_with_memory_limit] -features = "lua51,vendored,async,send,serialize,macros" +features = "lua51,vendored,async,send,serde,macros" rustflags = "--cfg force_memory_limit" [luau] -features = "luau,async,send,serialize,macros" +features = "luau,async,send,serde,macros" [luau_with_memory_limit] -features = "luau,async,send,serialize,macros" +features = "luau,async,send,serde,macros" rustflags = "--cfg force_memory_limit" diff --git a/tests/serde.rs b/tests/serde.rs index 9e3d5984..8f104eaf 100644 --- a/tests/serde.rs +++ b/tests/serde.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "serialize")] +#![cfg(feature = "serde")] use std::collections::HashMap; use std::error::Error as StdError; diff --git a/tests/userdata.rs b/tests/userdata.rs index 63f9e0f5..9dc93d99 100644 --- a/tests/userdata.rs +++ b/tests/userdata.rs @@ -38,7 +38,7 @@ fn test_userdata() -> Result<()> { #[test] fn test_methods() -> Result<()> { - #[cfg_attr(feature = "serialize", derive(serde::Serialize))] + #[cfg_attr(feature = "serde", derive(serde::Serialize))] struct MyUserData(i64); impl UserData for MyUserData { @@ -81,7 +81,7 @@ fn test_methods() -> Result<()> { check_methods(&lua, lua.create_userdata(MyUserData(42))?)?; // Additionally check serializable userdata - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] check_methods(&lua, lua.create_ser_userdata(MyUserData(42))?)?; Ok(()) @@ -306,7 +306,7 @@ fn test_userdata_take() -> Result<()> { } } - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] impl serde::Serialize for MyUserdata { fn serialize(&self, serializer: S) -> std::result::Result where @@ -364,7 +364,7 @@ fn test_userdata_take() -> Result<()> { check_userdata_take(&lua, userdata, rc)?; // Additionally check serializable userdata - #[cfg(feature = "serialize")] + #[cfg(feature = "serde")] { let rc = Arc::new(18); let userdata = lua.create_ser_userdata(MyUserdata(rc.clone()))?; From 62f84828f2870aa0bf8ac5a9c85172952fca32b4 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Thu, 12 Jun 2025 13:42:26 +0100 Subject: [PATCH 7/7] Open some doc(hidden) functionality --- src/buffer.rs | 1 - src/thread.rs | 1 - src/vector.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 0ee163ff..181e3696 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -25,7 +25,6 @@ impl Buffer { } /// Returns `true` if the buffer is empty. - #[doc(hidden)] pub fn is_empty(&self) -> bool { self.len() == 0 } diff --git a/src/thread.rs b/src/thread.rs index 520f0637..13d95532 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -472,7 +472,6 @@ impl Thread { /// ``` #[cfg(any(feature = "luau", doc))] #[cfg_attr(docsrs, doc(cfg(feature = "luau")))] - #[doc(hidden)] pub fn sandbox(&self) -> Result<()> { let lua = self.0.lua.lock(); let state = lua.state(); diff --git a/src/vector.rs b/src/vector.rs index 462cafac..c292e5d9 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -38,7 +38,6 @@ impl Vector { } /// Creates a new vector with all components set to `0.0`. - #[doc(hidden)] pub const fn zero() -> Self { Self([0.0; Self::SIZE]) }