pub struct RuntimeState {
pub nodes: BTreeMap<String, NodeState>,
}Expand description
What is true of a node in a running process, and of nothing on a published page.
A graph is definitions: they are the same in a static build and in a server, and they
are what compose derives. This is the overlay a consumer with a process to ask
lays over them, keyed by node id. It is deliberately not a field of Node: a node
that could carry runtime state would carry it into the static projection, where it
would be a value nobody can refresh and a reader cannot distinguish from a current
one.
Fields§
§nodes: BTreeMap<String, NodeState>Node id to what the process says about it now.
Implementations§
Source§impl RuntimeState
impl RuntimeState
Sourcepub fn narrowed_to(&self, graph: &Graph) -> RuntimeState
pub fn narrowed_to(&self, graph: &Graph) -> RuntimeState
The observations that name a node of this graph, and no others.
An observing process knows about subsystems, not about one graph’s vocabulary, so what it offers is wider than what any graph can show. Narrowing here rather than at each consumer is what keeps the overlay keyed by node id: an entry that survives names a node, and a renderer can look every key up.
use majordomus_cli::graph::{Builder, Node, NodeState, RuntimeState};
let mut b = Builder::new("g", "G", "one node", "the composed registry")
.node_kind("module", "a subsystem");
b.node(Node {
id: "module:mesh".into(), kind: "module".into(), label: "mesh".into(),
summary: None, route: None, source: None, status: None, external: false,
facts: Default::default(),
});
let graph = b.finish();
let mut observed = RuntimeState::default();
for id in ["module:mesh", "module:not-in-this-graph"] {
observed.nodes.insert(id.into(), NodeState { status: "ok".into(), detail: None });
}
let overlay = observed.narrowed_to(&graph);
assert_eq!(overlay.nodes.keys().map(String::as_str).collect::<Vec<_>>(), ["module:mesh"]);Sourcepub fn of(&self, node_id: &str) -> Option<&NodeState>
pub fn of(&self, node_id: &str) -> Option<&NodeState>
What the process says about one node now, if anything.
None is the ordinary answer, not a failure: a graph names more than any one
process observes, so a renderer draws the declared status alone for those nodes.
use majordomus_cli::graph::{NodeState, RuntimeState};
let mut observed = RuntimeState::default();
observed.nodes.insert(
"module:mesh".into(),
NodeState { status: "ready".into(), detail: Some("2 peers".into()) },
);
assert_eq!(observed.of("module:mesh").map(|s| s.status.as_str()), Some("ready"));
assert!(observed.of("module:nothing-observed-it").is_none());Trait Implementations§
Source§impl Clone for RuntimeState
impl Clone for RuntimeState
Source§fn clone(&self) -> RuntimeState
fn clone(&self) -> RuntimeState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RuntimeState
impl Debug for RuntimeState
Source§impl Default for RuntimeState
impl Default for RuntimeState
Source§fn default() -> RuntimeState
fn default() -> RuntimeState
Source§impl<'de> Deserialize<'de> for RuntimeState
impl<'de> Deserialize<'de> for RuntimeState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for RuntimeState
Source§impl JsonSchema for RuntimeState
impl JsonSchema for RuntimeState
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for RuntimeState
impl PartialEq for RuntimeState
Source§fn eq(&self, other: &RuntimeState) -> bool
fn eq(&self, other: &RuntimeState) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for RuntimeState
impl Serialize for RuntimeState
impl StructuralPartialEq for RuntimeState
Auto Trait Implementations§
impl Freeze for RuntimeState
impl RefUnwindSafe for RuntimeState
impl Send for RuntimeState
impl Sync for RuntimeState
impl Unpin for RuntimeState
impl UnsafeUnpin for RuntimeState
impl UnwindSafe for RuntimeState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.