Struct Invoke

Source
pub struct Invoke<C, A = JsValue> { /* private fields */ }
Expand description

A type used to configure an invoke operation.

Implementations§

Source§

impl<C, A> Invoke<C, A>

Source

pub fn with_args<T>(self, args: T) -> Invoke<C, T::Js>
where T: ToArgs,

Invokes a command with arguments on the backend.

§Passing a serializable type

To send a custom serializable type as arguments, use the helper args function.

use {gloo::console, serde::Serialize};

#[derive(Serialize)]
struct User<'str> {
    name: &'str str,
    pass: &'str str,
}

let user = User {
    name: "anon",
    pass: "p@$$w0rD",
};

let args = tauri_wasm::args(&user)?;
let message = tauri_wasm::invoke("login").with_args(args).await?;
console::log!("logged on backend", message);
§Passing a JS object

Thanks to the wasm_bindgen attribute you can convert your type into a JS value. To pass the value as arguments implement the ToArgs trait.

use {
    gloo::console,
    tauri_wasm::invoke::ToArgs,
    wasm_bindgen::prelude::*,
};

#[wasm_bindgen(getter_with_clone)]
struct User {
    name: String,
    pass: String,
}

impl ToArgs for User {
    type Js = JsValue;

    fn to_args(self) -> Self::Js {
        // wasm_bindgen attribute implements
        // convertion into JS value
        JsValue::from(self)
    }
}

let user = User {
    name: "anon".to_owned(),
    pass: "p@$$w0rD".to_owned(),
};

let message = tauri_wasm::invoke("login").with_args(user).await?;
console::log!("logged on backend", message);
Source

pub fn with_options(self, opts: Options) -> Self

Invokes a command with options on the backend.

§Example
use {gloo::console, tauri_wasm::invoke::Options};

let opts = Options::from_record([
    ("secret", "2"),
    ("data", "3"),
])?;

let message = tauri_wasm::invoke("send").with_options(opts).await?;
console::log!("received from backend", message);

Trait Implementations§

Source§

impl<C, A> IntoFuture for Invoke<C, A>
where C: AsRef<JsValue>, A: AsRef<JsValue>,

Source§

type Output = Result<JsValue, Error>

The output that the future will produce on completion.
Source§

type IntoFuture = InvokeFuture

Which kind of future are we turning this into?
Source§

fn into_future(self) -> Self::IntoFuture

Creates a future from a value. Read more

Auto Trait Implementations§

§

impl<C, A> Freeze for Invoke<C, A>
where C: Freeze, A: Freeze,

§

impl<C, A> RefUnwindSafe for Invoke<C, A>

§

impl<C, A = JsValue> !Send for Invoke<C, A>

§

impl<C, A = JsValue> !Sync for Invoke<C, A>

§

impl<C, A> Unpin for Invoke<C, A>
where C: Unpin, A: Unpin,

§

impl<C, A> UnwindSafe for Invoke<C, A>
where C: UnwindSafe, A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.