Skip to main content

impl_wire_string

Macro impl_wire_string 

Source
macro_rules! impl_wire_string {
    ($ty:ty $(,)?) => { ... };
    ($ty:ty, parse = $parse:expr, format = $format:expr $(,)?) => { ... };
    ($ty:ty, parse = $parse:expr $(,)?) => { ... };
}
Expand description

Implements the traits for a type that crosses as a String, so a malformed string is a WireError::Parse rather than a throw from inside FromWasmAbi.

  • impl_wire_string!(T) parses with FromStr and formats with Display.
  • impl_wire_string!(T, parse = f, format = g) takes f: FnOnce(String) -> Result<T, E> and g: FnOnce(T) -> String.
  • impl_wire_string!(T, parse = f) implements only FromWasm, for a type JavaScript never receives.

Also implements wasm_bindgen’s ABI traits through the same conversion, so the type needs no hand-written WasmDescribe / FromWasmAbi / IntoWasmAbi. from_abi cannot fail, so it throws on a malformed string.