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 WasmDescribe and, with a format, IntoWasmAbi through the same conversion, for extern "C" imports that pass the type to JavaScript. There is no FromWasmAbi: a value coming from JavaScript goes through FromWasm, so a malformed string is an Err rather than a throw.