Skip to content

Commit

Permalink
Seal HostFunctionKind trait
Browse files Browse the repository at this point in the history
  • Loading branch information
silwol committed Aug 5, 2022
1 parent 848cadb commit 72fa8a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/api/src/js/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions lib/api/src/sys/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 72fa8a1

Please sign in to comment.