diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a0be1e5..8d8e51f 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 65ac1ba..1cc3ab7 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 c0c3e26..ec41d3d 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 42b2008..0ee163f 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 1f24396..c20a39e 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 dc15737..e1589ce 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 eeeaea2..a3a0320 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 f475214..1b85a76 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 dfc7383..dbe4c2b 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 8efb714..b7de97f 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 9c86102..6304d48 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 9222868..4b62705 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 9bdfbd8..a568485 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 538e33d..f70399c 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 119f147..cfc1325 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 57a5a96..462cafa 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 71c73a3..48bd33f 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 9e3d598..8f104ea 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 63f9e0f..9dc93d9 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()))?;