dioxus_liveview/adapters/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::future::Future;

use dioxus_core::{Element, VirtualDom};

#[cfg(feature = "axum")]
pub mod axum_adapter;
#[cfg(feature = "axum")]
pub use axum_adapter::*;

/// A trait for servers that can be used to host a LiveView app.
pub trait LiveviewRouter {
    /// Create a new router.
    fn create_default_liveview_router() -> Self;

    /// Add a liveview route to the server from a component
    fn with_app(self, route: &str, app: fn() -> Element) -> Self
    where
        Self: Sized,
    {
        self.with_virtual_dom(route, move || VirtualDom::new(app))
    }

    /// Add a liveview route to the server from a virtual dom.
    fn with_virtual_dom(
        self,
        route: &str,
        app: impl Fn() -> VirtualDom + Send + Sync + 'static,
    ) -> Self;

    /// Start the server on an address.
    fn start(self, address: impl Into<std::net::SocketAddr>) -> impl Future<Output = ()>;
}