Skip to content

Enforcing/validating the input of a function to not be undefined #2282

Discussion options

You must be logged in to vote

You can use Either:

#[napi]
pub fn example(env: Env, maybe_callback: Either<Function<(String), ()>, Unknown>) -> napi::Result<()> {
  match maybe_callback {
    Either::A(callback) => {
      callback.call("hi".to_owned())?;
    }
    Either::B(whatever) => {},
  }
  Ok(())
}

Replies: 1 comment

Comment options

Brooooooklyn
Oct 1, 2024
Maintainer Sponsor

You must be logged in to vote
0 replies
Answer selected by ashley-hawkins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants