Crate derive_jserror

source ·
Expand description

This library provides a convenience derive macro for impl From<ErrorType> for JsValue.

Example

This example uses the thiserror crate to simplify the example, but it should work for any type that implements std::error::Error.

use derive_jserror::JsError;
use wasm_bindgen::prelude::*;
use thiserror::Error;

#[derive(Error, JsError, Debug)]
#[error("test error type")]
struct TestError;

#[wasm_bindgen]
pub fn func_returns_result() -> Result<(), TestError> {
    Err(TestError)
}

Derive Macros