Skip to main content

StateSource

Trait StateSource 

Source
pub trait StateSource {
    // Required method
    fn snapshot(&mut self) -> State;

    // Provided methods
    fn select(&mut self, key: &str) -> bool { ... }
    fn command(&mut self, command: &Command) -> Result<(), CommandError> { ... }
}
Expand description

Produces the current State snapshot whenever the dashboard asks for one.

The serving layer calls snapshot to answer GET /state and again on each live-update tick, so an implementation should return the latest view of the node cheaply. It takes &mut self so a source may advance internal state (a mock its clock, a real node its smoothing) as it is polled.

Required Methods§

Source

fn snapshot(&mut self) -> State

Returns the node’s current state snapshot.

§Returns

The latest language-neutral State to render.

Provided Methods§

Source

fn select(&mut self, key: &str) -> bool

Switches a named view, for development and debugging only.

The serving layer calls this when a request carries a ?scenario= parameter, so a single running dev server can be flipped through every state the UI must handle. A real node has nothing to switch, so the default ignores the request.

§Arguments
  • key - the requested view’s identifier.
§Returns

true if the source switched to key, false if it does not recognize it.

Source

fn command(&mut self, command: &Command) -> Result<(), CommandError>

Carries out an authenticated control command, changing the node’s state.

The serving layer calls this only after a command has been authenticated, so an implementation may act on it directly. A read-only source rejects every command, which is the default.

§Arguments
  • command - the action to carry out.
§Returns

Ok(()) once the command has been applied; its effect shows in the next snapshot.

§Errors

Returns a CommandError if the source does not support the command, the target is unknown, or the action is not allowed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§