pub struct Server { /* private fields */ }Expand description
A bound-but-not-yet-serving server: bind and serve are split so the caller can print the real URL (OS-assigned port included) before the accept loop starts.
Implementations§
Source§impl Server
impl Server
Sourcepub async fn bind(
document: &Document,
full_view: &ViewModel,
port: u16,
) -> Result<Self, ServeError>
pub async fn bind( document: &Document, full_view: &ViewModel, port: u16, ) -> Result<Self, ServeError>
Bind 127.0.0.1:port (0 = OS-assigned) around a snapshot of document, answering
expand-on-demand requests against full_view — the same ViewModel document was
built from, before its payload envelope truncated anything. The caller keeps that
pre-envelope copy around (typically a clone taken right before Document::new); this
crate cannot reconstruct it from document alone, since truncation is destructive.
Loopback is not a default, it is the only path: no widen flag exists in this crate (D6 — traces carry prompts, tool args, and whatever secrets leaked into them, so “local, no account” must be literally true).
§Errors
ServeError::Bind when the loopback bind fails (port in use).
Sourcepub async fn bind_with_assets<A: RustEmbed + 'static>(
document: &Document,
full_view: &ViewModel,
port: u16,
) -> Result<Self, ServeError>
pub async fn bind_with_assets<A: RustEmbed + 'static>( document: &Document, full_view: &ViewModel, port: u16, ) -> Result<Self, ServeError>
bind, generic over the embedded bundle — the seam that lets tests
(and any embedder) supply their own assets.
§Errors
ServeError::Bind when the loopback bind fails; ServeError::BundleMissing
(checked BEFORE binding — a startup failure must never leave a port claimed) when
the bundle has no index.html.
Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
The address actually bound — the one true source for the URL the CLI prints.
Sourcepub async fn serve(self) -> Result<(), ServeError>
pub async fn serve(self) -> Result<(), ServeError>
Run the accept loop until the future is dropped.
§Errors
ServeError::Serve if the accept loop fails after a successful bind.