Skip to main content

Crate axum_wire

Crate axum_wire 

Source
Expand description

§axum-wire

Laravel Livewire-like server-driven reactive UI components for Axum.

Components are Rust structs whose state lives on the server. User interactions (clicks, input changes, etc.) trigger AJAX requests that update state server-side, re-render HTML, and morph the DOM — no full page reload needed.

§How it works

  1. A component struct derives Component (+ Serialize, Deserialize, optionally Default)
  2. The #[wire_actions] macro on the impl block registers render(), optional mount(), and actions
  3. On first load, the component is mounted, rendered to HTML, and its state serialized as a JSON “snapshot” embedded in a data-wire-snapshot attribute
  4. A small JS runtime intercepts wire:click, wire:submit, wire:model etc., sends the snapshot + action name to the server via fetch()
  5. The server deserializes the snapshot, calls the action, re-renders, and returns the new HTML + snapshot
  6. The JS runtime uses morphdom to diff and patch the DOM in-place

Re-exports§

pub use futures;
pub use inventory;
pub use serde_json;
pub use tokio;
pub use subsecond;
pub use axum_extra;
pub use tower;

Modules§

extract
Types and traits for extracting data from requests.
html_elements
Typed HTML elements and attributes for IDE support.

Macros§

html
JSX-like HTML macro that produces a String.

Structs§

ActionEffects
Side-effects queued during an action (JS commands, redirect, skip render).
ActionScope
RAII guard that scopes action effects to a single call_action invocation. Since actions are synchronous (&mut self), no interleaving is possible.
ComponentFactory
DispatchEvent
EventListenerMeta
LayoutContext
Context passed to layout functions when rendering a page.
StoredPathParams
Custom extension type for storing path params during AJAX round-trips.
UrlFieldMeta
Metadata for a field annotated with #[url].
WireApp
WireContext
Request context available to wire components.
WireRender
WireResponse
WireStoredContext
Serializable context embedded in the component snapshot so that path params and other route information survive AJAX round-trips.
WireTagFragment
WireTagIter

Enums§

WireError

Constants§

WIRE_JS
The JS runtime that powers wire: directives on the client. Ships Alpine.js + morphdom + the $wire proxy.
WIRE_SCRIPTS
The JavaScript runtime (<script> tags) that powers wire: directives. Place in <body> just before </body>, or use @wireScripts in file layouts.
WIRE_STYLES
CSS styles for wire components (loading states, etc.). Place in <head>, or use @wireStyles in file layouts.

Traits§

CollectHtml
ComponentMeta
Auto-implemented by the derive macro to provide the component’s wire name.
HtmlFragment
WireRenderTagIter
Trait fallback — matches Iterator, chosen when inherent doesn’t match.
WireRouter

Functions§

connect_devtools
Connect to the Dioxus devtools for hot-patching.
default_layout
Built-in default layout — a minimal HTML page.
dispatch_event
Dispatch a browser event from the component root.
dispatch_event_targeted
Dispatch a browser event with optional targeting.
get_wire_ctx
Get the current WireContext from the task-local storage.
layout_from_str
Create a layout function from an HTML template string.
mount_component
Mount a component by name and return the full HTML (including wrapper).
mount_component_sync
Synchronous mount — used by html! macro for sub-components where we’re already inside a sync render() context.
mount_component_with_options_sync
Synchronous mount with props + event listeners for sub-components.
mount_component_with_props
Mount a component with initial prop values (async).
mount_component_with_props_sync
Synchronous mount with props — used by html! macro for <Counter count=42 />.
mount_component_with_query
Mount a component, merging URL query parameters into #[url] fields.
push_js
Push a JS command. Called by generated self.js().
push_response_extension
Queue a response extension to be inserted into the HTTP response.
render_component_html
Wraps a component’s rendered HTML with the wire root element and snapshot data.
render_component_html_with_listeners
Same as render_component_html, but attaches event listeners that map browser events to wire actions for component tags using @event={Self::action}.
render_html_fragment
set_redirect
Set a redirect URL. Called by generated self.redirect().
set_skip_render
Mark current action to skip rendering. Called by generated self.skip_render().
with_wire_ctx
Run an async block with the given WireContext set in task-local storage.

Type Aliases§

LayoutFn
MountFn
MountWithPropsFn
Mount with props: receives a JSON object of initial field values.
UpdateFn
Async-aware function types for the component factory.
WireResult

Attribute Macros§

on
wire_actions

Derive Macros§

Component