Seal LuaSerdeExt/TableExt/AnyUserDataExt

This commit is contained in:
Alex Orlenko 2023-03-19 02:38:21 +00:00
parent 6a647f58be
commit 781ded573a
No known key found for this signature in database
GPG Key ID: 4C150C250863B96D
4 changed files with 9 additions and 3 deletions

View File

@ -240,4 +240,7 @@ pub(crate) mod private {
impl Sealed for Error {}
impl<T> Sealed for std::result::Result<T, Error> {}
impl Sealed for Lua {}
impl Sealed for Table<'_> {}
impl Sealed for AnyUserData<'_> {}
}

View File

@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
use crate::error::Result;
use crate::ffi;
use crate::lua::Lua;
use crate::private::Sealed;
use crate::table::Table;
use crate::types::LightUserData;
use crate::util::check_stack;
@ -15,7 +16,7 @@ use crate::value::Value;
/// Trait for serializing/deserializing Lua values using Serde.
#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))]
pub trait LuaSerdeExt<'lua> {
pub trait LuaSerdeExt<'lua>: Sealed {
/// A special value (lightuserdata) to encode/decode optional (none) values.
///
/// Requires `feature = "serialize"`

View File

@ -11,6 +11,7 @@ use {
use crate::error::{Error, Result};
use crate::ffi;
use crate::function::Function;
use crate::private::Sealed;
use crate::types::{Integer, LuaRef};
use crate::util::{assert_stack, check_stack, StackGuard};
use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Nil, Value};
@ -753,7 +754,7 @@ impl<'lua> AsRef<Table<'lua>> for Table<'lua> {
}
/// An extension trait for `Table`s that provides a variety of convenient functionality.
pub trait TableExt<'lua> {
pub trait TableExt<'lua>: Sealed {
/// Calls the table as function assuming it has `__call` metamethod.
///
/// The metamethod is called with the table as its first argument, followed by the passed arguments.

View File

@ -1,4 +1,5 @@
use crate::error::{Error, Result};
use crate::private::Sealed;
use crate::userdata::{AnyUserData, MetaMethod};
use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Value};
@ -6,7 +7,7 @@ use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Value};
use {futures_core::future::LocalBoxFuture, futures_util::future};
/// An extension trait for [`AnyUserData`] that provides a variety of convenient functionality.
pub trait AnyUserDataExt<'lua> {
pub trait AnyUserDataExt<'lua>: Sealed {
/// Gets the value associated to `key` from the userdata, assuming it has `__index` metamethod.
fn get<K: IntoLua<'lua>, V: FromLua<'lua>>(&self, key: K) -> Result<V>;