LazyLoader

Struct LazyLoader 

Source
pub struct LazyLoader<Args, Ret> { /* private fields */ }
Expand description

A lazy loader that can be used to load a function from a split out .wasm file.

§Example

To use the split loader, you must first create the loader using the lazy_loader macro. This macro requires the complete signature of the function you want to load. The extern abi string denotes which module the function should be loaded from. If you don’t know which module to use, use auto and wasm-split will automatically combine all the modules into one.

static LOADER: wasm_split::LazyLoader<Args, Ret> = wasm_split::lazy_loader!(extern "auto" fn SomeFunction(args: Args) -> Ret);

fn SomeFunction(args: Args) -> Ret {
    // Implementation
}

§The #[component(lazy)] macro

If you’re using wasm-split with Dioxus, the #[component(lazy)] macro is provided that wraps the lazy loader with suspense. This means that the component will suspense until its body has been loaded.

fn app() -> Element {
    rsx! {
        Suspense {
            fallback: rsx! { "Loading..." },
            LazyComponent { abc: 0 }
        }
    }
}

#[component(lazy)]
fn LazyComponent(abc: i32) -> Element {
    rsx! {
        div {
            "This is a lazy component! {abc}"
        }
    }
}

Implementations§

Source§

impl<Args, Ret> LazyLoader<Args, Ret>

Source

pub const fn preloaded(f: fn(Args) -> Ret) -> Self

Create a new lazy loader that is already resolved.

Source

pub async fn load(&'static self) -> bool

Load the lazy loader, returning an boolean indicating whether it loaded successfully

Source

pub fn call(&'static self, args: Args) -> Result<Ret>

Call the lazy loader with the given arguments

Auto Trait Implementations§

§

impl<Args, Ret> Freeze for LazyLoader<Args, Ret>

§

impl<Args, Ret> RefUnwindSafe for LazyLoader<Args, Ret>

§

impl<Args, Ret> Send for LazyLoader<Args, Ret>

§

impl<Args, Ret> Sync for LazyLoader<Args, Ret>

§

impl<Args, Ret> Unpin for LazyLoader<Args, Ret>

§

impl<Args, Ret> UnwindSafe for LazyLoader<Args, Ret>

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.