Skip to main content

livewire/
lib.rs

1//! # Livewire for Rust
2//!
3//! Livewire renders a component on the server, sends the browser a signed snapshot of its state,
4//! and answers the browser's updates with new HTML and effects. This crate ports the server half of
5//! Livewire 4.x to Laravel for Rust, and reuses Livewire's own browser runtime unchanged.
6//!
7//! A component is a Rust struct whose fields cross the wire, plus an inherent implementation that
8//! publishes its actions:
9//!
10//! ```ignore
11//! use livewire::{LivewireComponent, component};
12//!
13//! #[derive(Default, LivewireComponent)]
14//! #[livewire(view = "livewire.counter")]
15//! struct Counter {
16//!     count: i32,
17//!     #[livewire(locked)]
18//!     id: String,
19//! }
20//!
21//! #[component]
22//! impl Counter {
23//!     fn mount(&mut self, count: Option<i32>) {
24//!         self.count = count.unwrap_or(0);
25//!         self.id = livewire::str::random(20);
26//!     }
27//!
28//!     fn increment(&mut self) {
29//!         self.count += 1;
30//!     }
31//! }
32//! ```
33//!
34//! The application registers its components once, in the provider:
35//!
36//! ```ignore
37//! use livewire::LivewireServiceProvider;
38//!
39//! laravel::Application::configure().with_providers(|providers| {
40//!     providers.add(LivewireServiceProvider::new(|components| {
41//!         components.register::<Counter>("counter");
42//!     }));
43//! });
44//! ```
45//!
46//! A page renders a component with [`livewire`]; a component that should render the whole document
47//! is mounted by its route with [`page::render_page`].
48//!
49//! | Module | Holds |
50//! | --- | --- |
51//! | [`mod@component`] | The authoring contract: [`Component`], [`LivewireState`], and the call envelope |
52//! | [`snapshot`] | The signed wire envelope and its checksum |
53//! | [`context`] | One request's mutable Livewire state, kept out of statics |
54//! | [`engine`] | The `.livewire` template engine |
55//! | [`registry`] | The components, synthesizers, and hooks an application registered |
56
57extern crate self as livewire;
58
59pub mod assets;
60pub mod checksum;
61pub mod commands;
62pub mod compile;
63pub mod component;
64pub mod config;
65pub mod context;
66pub mod engine;
67pub mod error;
68pub mod frontend;
69pub mod handlers;
70pub mod hooks;
71pub mod html;
72pub mod jinja_helpers;
73#[cfg(feature = "database")]
74pub mod models;
75pub mod page;
76pub mod persistent;
77pub mod provider;
78pub mod registry;
79pub mod render;
80pub mod routes;
81pub mod session;
82pub mod snapshot;
83pub mod synthesizers;
84pub mod testing;
85pub mod uploads;
86
87pub use self::component::{Call, Component, ComponentContext, ComponentView, LivewireState, Params};
88pub use self::config::LivewireConfig;
89pub use self::provider::LivewireServiceProvider;
90pub use self::registry::ComponentRegistry;
91pub use livewire_rust_macros::{LivewireComponent, component};
92
93/// The items generated code names, which an application never writes.
94#[doc(hidden)]
95pub mod __private {
96    pub use async_trait::async_trait;
97    pub use serde_json;
98    // The generated `validation_rules` builds these, in the consuming crate's name space.
99    pub use laravel::validation::{Rule, Rules};
100}
101pub use self::component::Result;
102pub use self::error::LivewireError;
103
104/// The string helpers the component IDs use, from the framework.
105pub use laravel::str;