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
- A component struct derives
Component(+Serialize,Deserialize, optionallyDefault) - The
#[wire_actions]macro on the impl block registersrender(), optionalmount(), and actions - On first load, the component is mounted, rendered to HTML, and its state
serialized as a JSON “snapshot” embedded in a
data-wire-snapshotattribute - A small JS runtime intercepts
wire:click,wire:submit,wire:modeletc., sends the snapshot + action name to the server via fetch() - The server deserializes the snapshot, calls the action, re-renders, and returns the new HTML + snapshot
- 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§
- Action
Effects - Side-effects queued during an action (JS commands, redirect, skip render).
- Action
Scope - RAII guard that scopes action effects to a single
call_actioninvocation. Since actions are synchronous (&mut self), no interleaving is possible. - Component
Factory - Dispatch
Event - Event
Listener Meta - Layout
Context - Context passed to layout functions when rendering a page.
- Stored
Path Params - Custom extension type for storing path params during AJAX round-trips.
- UrlField
Meta - Metadata for a field annotated with
#[url]. - WireApp
- Wire
Context - Request context available to wire components.
- Wire
Render - Wire
Response - Wire
Stored Context - Serializable context embedded in the component snapshot so that path params and other route information survive AJAX round-trips.
- Wire
TagFragment - Wire
TagIter
Enums§
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@wireScriptsin file layouts. - WIRE_
STYLES - CSS styles for wire components (loading states, etc.).
Place in
<head>, or use@wireStylesin file layouts.
Traits§
- Collect
Html - Component
Meta - Auto-implemented by the derive macro to provide the component’s wire name.
- Html
Fragment - Wire
Render TagIter - Trait fallback — matches Iterator, chosen when inherent doesn’t match.
- Wire
Router
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
WireContextfrom 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 syncrender()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
WireContextset in task-local storage.
Type Aliases§
- Layout
Fn - MountFn
- Mount
With Props Fn - Mount with props: receives a JSON object of initial field values.
- Update
Fn - Async-aware function types for the component factory.
- Wire
Result