Skip to main content

WireApp

Struct WireApp 

Source
pub struct WireApp { /* private fields */ }

Implementations§

Source§

impl WireApp

Source

pub fn new() -> Self

Source

pub fn layout<F>(self, name: &str, f: F) -> Self
where F: Fn(LayoutContext) -> String + Send + Sync + 'static,

Register a named layout function.

The name "default" is special — it’s used when no #[layout] attribute is set on the component and no per-route override is given.

ⓘ
WireApp::new()
    .layout("default", |ctx| { ... })
    .layout("auth", auth_layout)
    .layout("admin", admin_layout)
Source

pub fn layout_str(self, name: &str, template: &str) -> Self

Register a layout from an HTML template string.

The template supports these placeholders:

  • @wireBody — the rendered component HTML
  • @wireScripts — the wire JS runtime <script> tags
  • @wireStyles — the wire CSS <style> tag
  • @wireTitle — the component’s wire name
ⓘ
WireApp::new()
    .layout_str("auth", include_str!("layouts/auth.html"))
Source

pub fn layout_file(self, name: &str, path: &str) -> Self

Register a layout from an HTML file path (read at startup).

The file supports the same placeholders as layout_str.

ⓘ
WireApp::new()
    .layout_file("auth", "layouts/auth.html")
§Panics

Panics if the file cannot be read.

Source

pub fn state<T: Clone + Send + Sync + 'static>(self, value: T) -> Self

Add shared application state accessible via ctx.state::<T>() in components.

ⓘ
let app = WireApp::new()
    .state(db_pool)
    .state(redis_client)
    .wire("/posts/{postId}", "post-view")
    .into_router();
Source

pub fn wire(self, path: &str, component_name: &str) -> Self

Register a wire component route. Layout is resolved from the component’s #[layout("name")] attribute, falling back to "default".

Source

pub fn wire_with<F>( self, path: &str, component_name: &str, layout_fn: F, ) -> Self
where F: Fn(LayoutContext) -> String + Send + Sync + 'static,

Register a wire component route with an explicit per-route layout function. This overrides any #[layout] attribute on the component.

Source

pub fn layer<L>(self, layer: L) -> Self
where L: Layer<Route> + Clone + Send + Sync + 'static, L::Service: Service<Request, Error = Infallible> + Clone + Send + Sync + 'static, <L::Service as Service<Request>>::Response: IntoResponse + 'static, <L::Service as Service<Request>>::Future: Send + 'static,

Apply a Tower layer/middleware to wire page routes.

Like axum::Router::layer, this applies to the routes that currently exist in the builder. Routes registered later are unaffected.

/_wire/update is intentionally not layered by Axum. Instead, during an AJAX update, axum-wire replays the layers associated with the original mounted route (tracked via __wire_ctx in the snapshot).

To scope middleware to a subset of routes, use group(...).

ⓘ
use tower_http::cors::CorsLayer;
use tower_http::compression::CompressionLayer;

WireApp::new()
    .wire("/", "counter")
    .layer(CorsLayer::permissive())
    .layer(CompressionLayer::new())
    .into_router();
Source

pub fn group<F>(self, f: F) -> Self
where F: FnOnce(Self) -> Self,

Build a scoped set of wire routes and layers, then merge them back.

This is useful when you want Axum-like layering on just a subset of routes without affecting the rest of the app.

ⓘ
WireApp::new()
    .wire("/", "home")
    .group(|app| {
        app.wire("/admin", "admin-dashboard")
            .wire("/admin/posts", "admin-posts")
            .layer(auth_layer)
    })
    .wire("/about", "about")
Source

pub fn merge(self, router: Router) -> Self

Source

pub fn into_router<S>(self) -> Router<S>
where S: Clone + Send + Sync + 'static,

Trait Implementations§

Source§

impl Default for WireApp

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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