Skip to main content

apply_topology_patch_ops

Function apply_topology_patch_ops 

Source
pub fn apply_topology_patch_ops(
    source: &Graph,
    patch: &TopologyPatch,
) -> Result<Graph>
Expand description

Applies a patch’s operations to a copy of source without compiling or validating the result. This is the editing surface for tools that build a topology incrementally (for example the Web-UI composer), where intermediate graphs are legitimately incomplete; validation runs later at save or run. Capability gating is the caller’s responsibility.

§Examples

use sim_kernel::{Expr, Symbol};
use sim_lib_topology::{PatchOp, TopologyPatch, apply_topology_patch_ops, parse_package};

let package = parse_package(
    "graph:\ntopology flow\nnode in verb=in\nnode out verb=out\nwire in -> out\n",
)
.unwrap();

let patch = TopologyPatch {
    ops: vec![PatchOp::SetMetadata {
        key: Symbol::new("note"),
        value: Expr::String("edited".to_owned()),
    }],
};
let edited = apply_topology_patch_ops(&package.graph, &patch).unwrap();

assert!(
    edited
        .metadata
        .iter()
        .any(|(key, _)| key == &Symbol::new("note"))
);