Skip to main content

LiveHub

Struct LiveHub 

Source
pub struct LiveHub { /* private fields */ }
Expand description

Holds the lowered app and its open connections; turns publish into targeted re-renders. With a live_handler set the re-render is a structural diff (design.md §10, A3); otherwise it is the broadcast-refresh full page (A1).

Implementations§

Source§

impl LiveHub

Source

pub fn new(wasm: Vec<u8>, handler: &str, db_path: &str) -> Self

Source

pub fn set_live_handler(&mut self, name: &str)

Opt this hub into diff-based push (design.md §10, A3): name is the app’s <handler>_live entry (the run_app_live envelope — full HTML on first render, the Change wire thereafter). Without this the hub stays broadcast-refresh (A1), unchanged.

Source

pub fn connect( &mut self, topics: Vec<String>, method: &str, path: &str, body: &str, ) -> Result<(u64, HttpResponse), RunError>

Open a connection for a page request. Returns its id and the initial rendered response. topics is what this page subscribes to. Any publishes during the initial render are discarded — a fresh page is its own latest state.

Source

pub fn connect_subscribed( &mut self, subs_handler: &str, method: &str, path: &str, body: &str, ) -> Result<(u64, HttpResponse), RunError>

Like connect but the page’s topics come from the app itself: a subscriptions(req) -> Response handler whose body is the whitespace-delimited topic list (the v1 ABI form of design.md §10’s subscriptions: Fn(Model) -> List<Topic> — pure, explicit, reviewed, no magic dependency capture). An empty body means the page subscribes to nothing.

Source

pub fn request( &self, method: &str, path: &str, body: &str, ) -> Result<HttpResponse, RunError>

A one-shot request that is not itself a live connection (e.g. the POST that mutates state and publishes). Publishes it performs are queued on this thread for the next drain_and_push.

Source

pub fn drain_and_push(&mut self) -> Result<Vec<(u64, HttpResponse)>, RunError>

Drain the topics published on this thread since the last call; for every connection subscribed to any of them, re-render (stateless: the same request against the new DB state) and return (conn_id, fresh response) to write down its socket. Unsubscribed connections are untouched.

Source

pub fn disconnect(&mut self, id: u64)

Drop a connection by id — called when its socket write fails (the client went away). After this the connection is no longer re-rendered by drain_and_push. Unknown ids are a no-op (an already-pruned conn double-reported as dead is not an error).

Source

pub fn connections(&self) -> usize

Open connection count (for observability/tests).

Source

pub fn is_diff(&self) -> bool

Diff-push mode (a live_handler is set)? Then pushes are the Change wire and the SSE stream sends no initial frame — the browser already has the server-rendered document and the baseline prior is held here. Broadcast mode sends the full page.

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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.