pub struct ObservedGraph {
pub graph: Graph,
pub runtime: RuntimeState,
}Expand description
The second projection of a graph: the definitions a static build publishes, and beside them what a process observes about them now.
The two are held apart on purpose. graph is byte-for-byte the value
derive() produced, so a reader can compare a served graph against a published one and
get equality; runtime is the overlay, which no published artifact carries and which
nothing but a live process can fill. A consumer that merged them would produce a
document that looks like the static projection, cannot be compared with it, and carries
values that go stale the moment they are written.
use majordomus_cli::graph::{Builder, Node, NodeState, ObservedGraph, 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: Some("declared".into()),
external: false, facts: Default::default(),
});
let graph = b.finish();
let mut observed = RuntimeState::default();
observed.nodes.insert("module:mesh".into(), NodeState { status: "ready".into(), detail: None });
let served = ObservedGraph::new(graph.clone(), &observed);
// the definitions are the published value, byte for byte; the observation sits beside them
assert_eq!(served.graph, graph);
assert_eq!(served.graph.nodes[0].status.as_deref(), Some("declared"));
assert_eq!(served.runtime.of("module:mesh").map(|s| s.status.as_str()), Some("ready"));Fields§
§graph: GraphThe composed definitions, unchanged.
runtime: RuntimeStateWhat this process observes about them, keyed by node id, narrowed to nodes the graph holds.
Implementations§
Source§impl ObservedGraph
impl ObservedGraph
Sourcepub fn new(graph: Graph, observed: &RuntimeState) -> ObservedGraph
pub fn new(graph: Graph, observed: &RuntimeState) -> ObservedGraph
Lay an observation over a graph. The graph is not touched, and observations that name no node of it are dropped.
use majordomus_cli::graph::{Builder, Node, NodeState, ObservedGraph, 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 mut observed = RuntimeState::default();
for id in ["module:mesh", "module:a-subsystem-this-graph-does-not-name"] {
observed.nodes.insert(id.into(), NodeState { status: "ok".into(), detail: None });
}
let served = ObservedGraph::new(b.finish(), &observed);
assert_eq!(served.runtime.nodes.len(), 1);
assert!(served.runtime.of("module:a-subsystem-this-graph-does-not-name").is_none());Trait Implementations§
Source§impl Clone for ObservedGraph
impl Clone for ObservedGraph
Source§fn clone(&self) -> ObservedGraph
fn clone(&self) -> ObservedGraph
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 ObservedGraph
impl Debug for ObservedGraph
Source§impl<'de> Deserialize<'de> for ObservedGraph
impl<'de> Deserialize<'de> for ObservedGraph
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 ObservedGraph
Source§impl JsonSchema for ObservedGraph
impl JsonSchema for ObservedGraph
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 ObservedGraph
impl PartialEq for ObservedGraph
Source§fn eq(&self, other: &ObservedGraph) -> bool
fn eq(&self, other: &ObservedGraph) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for ObservedGraph
impl Serialize for ObservedGraph
impl StructuralPartialEq for ObservedGraph
Auto Trait Implementations§
impl Freeze for ObservedGraph
impl RefUnwindSafe for ObservedGraph
impl Send for ObservedGraph
impl Sync for ObservedGraph
impl Unpin for ObservedGraph
impl UnsafeUnpin for ObservedGraph
impl UnwindSafe for ObservedGraph
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.