Seal HostFunctionKind trait

This commit is contained in:
Wolfgang Silbermayr
2022-08-05 12:52:26 +02:00
parent f8f12654d4
commit dcb34971ad
2 changed files with 21 additions and 1 deletions

View File

@@ -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.