Skip to main content

AsyncRender

Trait AsyncRender 

Source
pub trait AsyncRender: Sync {
    // Required method
    fn render_into_async<'life0, 'life1, 'async_trait>(
        &'life0 self,
        r: &'life1 mut dyn Renderer,
    ) -> RenderFuture<'async_trait>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn render_slots_async<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        r: &'life1 mut dyn Renderer,
        _slots: Slots<'life2>,
    ) -> RenderFuture<'async_trait>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

The async counterpart of Render, for content whose template genuinely .awaits something.

async fn in a trait is not dyn-safe — the compiler cannot size a call through &dyn AsyncRender without knowing the concrete future — so, like the async-trait crate, these methods hand back an explicitly boxed future instead. That is one allocation per render, which is exactly the cost Render stays free of: the derive only emits AsyncRender for a .dmk that contains .await; everything else keeps rendering through the plain, allocation-free Render.

Every Render implementor gets AsyncRender for free, through the blanket impl below — its future has nothing to poll but a sync call that already ran to completion. That is what lets an async template embed a sync child exactly as cheaply as a sync template can; the reverse does not hold, since a genuinely async component has no sensible Render to fall back to (running it would mean blocking on a future inside whatever executor is already driving the caller).

Required Methods§

Source

fn render_into_async<'life0, 'life1, 'async_trait>( &'life0 self, r: &'life1 mut dyn Renderer, ) -> RenderFuture<'async_trait>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Write this content into r, with no slots filled.

Provided Methods§

Source

fn render_slots_async<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, r: &'life1 mut dyn Renderer, _slots: Slots<'life2>, ) -> RenderFuture<'async_trait>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Write this content into r, resolving its <slot>s against slots.

The derive overrides this with the lowered template and redirects render_into_async here with Slots::EMPTY, mirroring Render::render_slots.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F> AsyncRender for AsyncFragment<F>
where F: for<'r> Fn(&'r mut dyn Renderer) -> RenderFuture<'r> + Sync,

Source§

impl<T: Render + Sync + ?Sized> AsyncRender for T