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>
impl<C, A> Invoke<C, A>
Sourcepub fn with_args<T>(self, args: T) -> Invoke<C, T::Js>where
T: ToArgs,
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);
Sourcepub fn with_options(self, opts: Options) -> Self
pub fn with_options(self, opts: Options) -> Self
Trait Implementations§
Source§impl<C, A> IntoFuture for Invoke<C, A>
impl<C, A> IntoFuture for Invoke<C, A>
Source§type IntoFuture = InvokeFuture
type IntoFuture = InvokeFuture
Which kind of future are we turning this into?
Source§fn into_future(self) -> Self::IntoFuture
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>
impl<C, A> RefUnwindSafe for Invoke<C, A>where
C: RefUnwindSafe,
A: RefUnwindSafe,
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>
impl<C, A> UnwindSafe for Invoke<C, A>where
C: UnwindSafe,
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more