Skip to main content

Server

Struct Server 

Source
pub struct Server<S> { /* private fields */ }
Expand description

The dashboard HTTP server, generic over whatever produces its state.

Build one with Server::new, optionally set the live-update cadence with Server::with_push_interval, then block in Server::run (plain TCP) or Server::run_on (a custom Transport).

§Examples

use pamoja_dashboard::{Assets, Server, State, StateSource, Status};

// Any StateSource works; a real node produces its live State here, and the
// `mock` feature's `Mock` is the hardware-free stand-in for development.
struct Node;
impl StateSource for Node {
    fn snapshot(&mut self) -> State {
        State { orgs: Vec::new(), status: Status::Ok, uptime_secs: None, demo: false }
    }
}

let server = Server::new(Node, Assets::Embedded);
server.run("127.0.0.1:8080").expect("serve");

Implementations§

Source§

impl<S: StateSource + Send + 'static> Server<S>

Source

pub fn new(source: S, assets: Assets) -> Self

Creates a server that renders source with assets.

Control is authenticated against a freshly generated pairing secret that nobody holds yet, so no client can issue commands until with_pairing_secret sets the secret the device actually shows. Read-only viewing needs no pairing.

§Arguments
  • source - the state source to serve, a real node or a Mock.
  • assets - where the page files come from, embedded or a directory.
§Returns

A server pushing live updates once a second by default.

Source

pub fn with_catalog(self, catalog: Catalog) -> Self

Serves a presentation Catalog at GET /catalog so the page can show the deployment’s custom sensors, stats, and theme.

Build the catalog from the profiles the deployment runs with Catalog::from_profiles. A catalog with nothing custom is not worth serving; skip this call and the page keeps its built-in defaults.

§Arguments
  • catalog - the presentation catalog to serve.
§Returns

The server, for chaining.

Source

pub fn with_pairing_secret(self, secret: impl Into<String>) -> Self

Sets the pairing secret a client must know to issue commands.

The secret is shown out of band (the device’s screen, a QR code, or the dev server’s console) and never crosses the network.

§Arguments
  • secret - the canonical pairing secret.
§Returns

The server, for chaining.

Source

pub fn with_push_interval(self, interval: Duration) -> Self

Sets how often the GET /events stream pushes a fresh snapshot.

§Arguments
  • interval - the delay between pushes.
§Returns

The server, for chaining.

Source

pub fn run(self, addr: impl ToSocketAddrs) -> Result<()>

Binds addr over plain TCP and serves forever.

§Arguments
  • addr - the address to listen on, such as "0.0.0.0:80".
§Returns

Never returns on success; it serves until the process ends.

§Errors

Returns the std::io::Error from binding the listener.

Source

pub fn run_on<T: Transport>(self, transport: T) -> Result<()>

Serves forever over a supplied Transport, one thread per connection.

This is the seam for a non-default transport, such as a future TLS transport for a capable tier.

§Arguments
  • transport - the source of connections.
§Returns

Never returns on success; it serves until the process ends.

§Errors

Returns a std::io::Error only if accepting fails unrecoverably; transient accept errors are skipped.

Auto Trait Implementations§

§

impl<S> Freeze for Server<S>

§

impl<S> RefUnwindSafe for Server<S>

§

impl<S> Send for Server<S>
where S: Send,

§

impl<S> Sync for Server<S>
where S: Send,

§

impl<S> Unpin for Server<S>

§

impl<S> UnsafeUnpin for Server<S>

§

impl<S> UnwindSafe for Server<S>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.