Struct leptos::AwaitProps

source ·
pub struct AwaitProps<T, Fut, FF, VF, V>
where Fut: Future<Output = T> + 'static, FF: Fn() -> Fut + 'static, V: IntoView, VF: Fn(&T) -> V + 'static, T: Serializable + 'static,
{ pub future: FF, pub blocking: bool, pub local: bool, pub children: VF, }
Expand description

Props for the Await component.

Allows you to inline the data loading for an async block or server function directly into your view. This is the equivalent of combining a create_resource that only loads once (i.e., with a source signal || ()) with a Suspense with no fallback.

Adding let:{variable name} to the props makes the data available in the children that variable name, when resolved.

async fn fetch_monkeys(monkey: i32) -> i32 {
    // do some expensive work
    3
}

view! {
    <Await
        future=|| fetch_monkeys(3)
        let:data
    >
        <p>{*data} " little monkeys, jumping on the bed."</p>
    </Await>
}

§Required Props

  • future: [FF]
    • A function that returns the Future that will the component will .await before rendering.
  • children: [VF]
    • A function that takes a reference to the resolved data from the future renders a view.

      §Syntax

      This can be passed in the view children of the <Await/> by using the let: syntax to specify the name for the data variable.

      view! {
          <Await
              future=|| fetch_monkeys(3)
              let:data
          >
              <p>{*data} " little monkeys, jumping on the bed."</p>
          </Await>
      }

      is the same as

      view! {
         <Await
             future=|| fetch_monkeys(3)
             children=|data| view! {
               <p>{*data} " little monkeys, jumping on the bed."</p>
             }
         />
      }

§Optional Props

  • blocking: bool
    • If true, the component will use create_blocking_resource, preventing the HTML stream from returning anything before future has resolved.
  • local: bool
    • If true, the component will use create_local_resource, this will always run on the local system and therefore its result type does not need to be Serializable.

Fields§

§future: FF

A function that returns the Future that will the component will .await before rendering.

§blocking: bool

If true, the component will use create_blocking_resource, preventing the HTML stream from returning anything before future has resolved.

§local: bool

If true, the component will use create_local_resource, this will always run on the local system and therefore its result type does not need to be Serializable.

§children: VF

A function that takes a reference to the resolved data from the future renders a view.

§Syntax

This can be passed in the view children of the <Await/> by using the let: syntax to specify the name for the data variable.

view! {
    <Await
        future=|| fetch_monkeys(3)
        let:data
    >
        <p>{*data} " little monkeys, jumping on the bed."</p>
    </Await>
}

is the same as

view! {
   <Await
       future=|| fetch_monkeys(3)
       children=|data| view! {
         <p>{*data} " little monkeys, jumping on the bed."</p>
       }
   />
}

Implementations§

source§

impl<T, Fut, FF, VF, V> AwaitProps<T, Fut, FF, VF, V>
where Fut: Future<Output = T> + 'static, FF: Fn() -> Fut + 'static, V: IntoView, VF: Fn(&T) -> V + 'static, T: Serializable + 'static,

source

pub fn builder() -> AwaitPropsBuilder<T, Fut, FF, VF, V, ((), (), (), ())>

Create a builder for building AwaitProps. On the builder, call .future(...), .blocking(...)(optional), .local(...)(optional), .children(...) to set the values of the fields. Finally, call .build() to create the instance of AwaitProps.

Trait Implementations§

source§

impl<T, Fut, FF, VF, V> IntoView for AwaitProps<T, Fut, FF, VF, V>
where Fut: Future<Output = T> + 'static, FF: Fn() -> Fut + 'static, V: IntoView, VF: Fn(&T) -> V + 'static, T: Serializable + 'static,

source§

fn into_view(self) -> View

Converts the value into View.

Auto Trait Implementations§

§

impl<T, Fut, FF, VF, V> Freeze for AwaitProps<T, Fut, FF, VF, V>
where FF: Freeze, VF: Freeze,

§

impl<T, Fut, FF, VF, V> RefUnwindSafe for AwaitProps<T, Fut, FF, VF, V>

§

impl<T, Fut, FF, VF, V> Send for AwaitProps<T, Fut, FF, VF, V>
where FF: Send, VF: Send,

§

impl<T, Fut, FF, VF, V> Sync for AwaitProps<T, Fut, FF, VF, V>
where FF: Sync, VF: Sync,

§

impl<T, Fut, FF, VF, V> Unpin for AwaitProps<T, Fut, FF, VF, V>
where FF: Unpin, VF: Unpin,

§

impl<T, Fut, FF, VF, V> UnwindSafe for AwaitProps<T, Fut, FF, VF, V>
where FF: UnwindSafe, VF: 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

§

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>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more