From dcb34971addac8d6e0acc10de189cb0156c08865 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Fri, 5 Aug 2022 12:52:26 +0200 Subject: [PATCH] Seal HostFunctionKind trait --- lib/api/src/js/externals/function.rs | 12 +++++++++++- lib/api/src/sys/externals/function.rs | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/api/src/js/externals/function.rs b/lib/api/src/js/externals/function.rs index 3c7bd3017c9..a74a3fa22e0 100644 --- a/lib/api/src/js/externals/function.rs +++ b/lib/api/src/js/externals/function.rs @@ -901,7 +901,7 @@ mod inner { /// the trait system to automatically generate the appropriate /// host functions. #[doc(hidden)] - pub trait HostFunctionKind {} + pub trait HostFunctionKind: private::HostFunctionKindSealed {} /// An empty struct to help Rust typing to determine /// when a `HostFunction` does have an environment. @@ -915,6 +915,16 @@ mod inner { impl HostFunctionKind for WithoutEnv {} + mod private { + //! Sealing the HostFunctionKind because it shouldn't be implemented + //! by any type outside. + //! See: + //! https://rust-lang.github.io/api-guidelines/future-proofing.html#c-sealed + pub trait HostFunctionKindSealed {} + impl HostFunctionKindSealed for super::WithEnv {} + impl HostFunctionKindSealed for super::WithoutEnv {} + } + /// Represents a low-level Wasm static host function. See /// `super::Function::new` and `super::Function::new_env` to learn /// more. diff --git a/lib/api/src/sys/externals/function.rs b/lib/api/src/sys/externals/function.rs index 1aa1c5f03c9..87bfa8237eb 100644 --- a/lib/api/src/sys/externals/function.rs +++ b/lib/api/src/sys/externals/function.rs @@ -1119,6 +1119,16 @@ mod inner { impl HostFunctionKind for WithoutEnv {} + mod private { + //! Sealing the HostFunctionKind because it shouldn't be implemented + //! by any type outside. + //! See: + //! https://rust-lang.github.io/api-guidelines/future-proofing.html#c-sealed + pub trait HostFunctionKindSealed {} + impl HostFunctionKindSealed for super::WithEnv {} + impl HostFunctionKindSealed for super::WithoutEnv {} + } + /// Represents a low-level Wasm static host function. See /// [`super::Function::new_typed`] and /// [`super::Function::new_typed_with_env`] to learn more.