Trait artemis::exchange::Extension[][src]

pub trait Extension: Sized + Clone + Send + Sync + 'static { }

An extension that may be passed by the user to provide additional request options to a third-party exchange. This is only here to allow for JS interop - The implementor of the exchange must deserialize JavaScript input to the best of their ability. Note that this may involve complex operations such as converting js_sys::Function to Rust closures or other advanced deserialization. This is not a simple serde-like deserialization.

An extension must always be Clone.

Example

use artemis::exchange::Extension;

#[derive(Clone)]
struct MyExtension(String);

impl Extension for MyExtension {
    #[cfg(target_arch = "wasm32")]
    fn from_js(value: JsValue) -> Option<Self> {
        use wasm_bindgen::JsCast;

        let cast = value.dyn_into::<String>();
        if let Ok(cast) = cast {
            Self(cast)
        } else { None }
    }
}

Implementors

Loading content...