Skip to main content

shelly/
lib.rs

1//! Core runtime primitives for Shelly LiveView.
2//!
3//! This crate intentionally avoids HTTP concerns. It defines the framework
4//! contract: events, server messages, HTML rendering, session lifecycle, and
5//! the `LiveView` trait.
6//!
7//! # Quick Example
8//!
9//! ```
10//! use shelly::{Context, Event, Html, LiveResult, LiveView};
11//!
12//! #[derive(Default)]
13//! struct Counter {
14//!     count: i64,
15//! }
16//!
17//! impl LiveView for Counter {
18//!     fn handle_event(&mut self, event: Event, _ctx: &mut Context) -> LiveResult {
19//!         if event.name == "inc" {
20//!             self.count += 1;
21//!         }
22//!         Ok(())
23//!     }
24//!
25//!     fn render(&self) -> Html {
26//!         Html::new(format!("<h1>{}</h1>", self.count))
27//!     }
28//! }
29//!
30//! let mut view = Counter::default();
31//! let mut ctx = Context::new("root");
32//! view.handle_event(Event::new("inc"), &mut ctx).expect("event should succeed");
33//! assert_eq!(view.render().as_str(), "<h1>1</h1>");
34//! ```
35
36mod component;
37mod context;
38mod error;
39mod event;
40mod form;
41mod html;
42mod invariants;
43mod live_view;
44mod nested;
45mod protocol;
46mod pubsub;
47mod replay;
48mod runtime;
49mod session;
50mod telemetry;
51
52pub use component::{ComponentId, ComponentRender, LiveComponent};
53pub use context::{Context, SessionId};
54pub use error::{LiveResult, ShellyError};
55pub use event::Event;
56pub use form::{dot_path, parse_path_segments, value_as_string, FormData, ValidationErrors};
57pub use html::{escape_html, Html, Template, TemplateSnapshot};
58pub use invariants::{
59    describe_client_message, describe_server_message, is_supported_protocol_version,
60    validate_client_message_invariants, validate_server_message_invariants,
61    validate_server_message_sequence, ProtocolAuthority, ProtocolDirection, ProtocolDurability,
62    ProtocolInstructionClass, ProtocolInstructionDescriptor, ProtocolInvariantViolation,
63    ProtocolOrdering, ProtocolRenderEffect, SUPPORTED_PROTOCOL_VERSIONS,
64};
65pub use live_view::LiveView;
66pub use nested::{NestedLiveViewId, NestedLiveViewSnapshot, NestedLiveViewState};
67pub use protocol::{
68    ChartAnnotation, ChartPoint, ClientMessage, DynamicSlotPatch, GridColumn, GridPinned, GridRow,
69    GridRowsWindow, GridSavedView, GridSort, GridSortDirection, GridState, InboxItem,
70    JsInteropDispatch, ResumeStatus, ServerMessage, StreamBatchOperation, StreamPosition, Toast,
71    ToastLevel, PROTOCOL_VERSION_V1,
72};
73pub use pubsub::{
74    PubSub, PubSubBackend, PubSubCapabilities, PubSubCommand, PubSubDeliveryScope, PubSubMessage,
75    PubSubOrdering, PubSubPresenceSnapshot, PubSubReceiveError, PubSubSubscription,
76    SessionAffinityRequirement,
77};
78pub use replay::{
79    replay_trace, ReplayReport, ReplayStepResult, ReplayStepStatus, SessionReplayMetadata,
80    SessionReplayTrace, SessionReplayTraceStep, SessionTraceRecorder, TimeTravelFrame,
81    TimeTravelInspector, TraceRedactionPolicy, TraceRedactionSummary, REPLAY_TRACE_FORMAT_VERSION,
82};
83pub use runtime::{RuntimeCommand, RuntimeEvent};
84pub use session::{LiveSession, INTERNAL_RENDER_FLUSH_EVENT};
85pub use telemetry::{
86    MemoryTelemetrySink, NoopTelemetrySink, TelemetryEvent, TelemetryEventKind, TelemetrySink,
87};