pub struct GraphBuilder { /* private fields */ }Expand description
Builder for assembling an initial graph document before handing it to runtime mutation APIs.
The builder keeps direct collection writes out of Graph’s public API while still making
fixtures, importers, and graph generators straightforward. Use GraphBuilder::build when the
result should satisfy graph invariants, or GraphBuilder::build_unchecked only for tests and
migrations that intentionally inspect invalid graphs.
Implementations§
Source§impl GraphBuilder
impl GraphBuilder
Sourcepub fn with_import(self, id: GraphId, import: GraphImport) -> Self
pub fn with_import(self, id: GraphId, import: GraphImport) -> Self
Adds or replaces an import.
Sourcepub fn with_symbol(self, id: SymbolId, symbol: Symbol) -> Self
pub fn with_symbol(self, id: SymbolId, symbol: Symbol) -> Self
Adds or replaces a symbol.
Sourcepub fn with_group(self, id: GroupId, group: Group) -> Self
pub fn with_group(self, id: GroupId, group: Group) -> Self
Adds or replaces a group.
Sourcepub fn with_sticky_note(self, id: StickyNoteId, note: StickyNote) -> Self
pub fn with_sticky_note(self, id: StickyNoteId, note: StickyNote) -> Self
Adds or replaces a sticky note.
Sourcepub fn with_binding(self, id: BindingId, binding: Binding) -> Self
pub fn with_binding(self, id: BindingId, binding: Binding) -> Self
Adds or replaces a binding.
Sourcepub fn insert_import(
&mut self,
id: GraphId,
import: GraphImport,
) -> Option<GraphImport>
pub fn insert_import( &mut self, id: GraphId, import: GraphImport, ) -> Option<GraphImport>
Inserts or replaces an import in-place.
Sourcepub fn update_import<R>(
&mut self,
id: &GraphId,
f: impl FnOnce(&mut GraphImport) -> R,
) -> Option<R>
pub fn update_import<R>( &mut self, id: &GraphId, f: impl FnOnce(&mut GraphImport) -> R, ) -> Option<R>
Updates an import in-place.
Sourcepub fn remove_import(&mut self, id: &GraphId) -> Option<GraphImport>
pub fn remove_import(&mut self, id: &GraphId) -> Option<GraphImport>
Removes an import in-place.
Sourcepub fn clear_imports(&mut self)
pub fn clear_imports(&mut self)
Clears imports in-place.
Sourcepub fn retain_imports(
&mut self,
f: impl FnMut(&GraphId, &mut GraphImport) -> bool,
)
pub fn retain_imports( &mut self, f: impl FnMut(&GraphId, &mut GraphImport) -> bool, )
Retains imports matching f.
Sourcepub fn insert_symbol(&mut self, id: SymbolId, symbol: Symbol) -> Option<Symbol>
pub fn insert_symbol(&mut self, id: SymbolId, symbol: Symbol) -> Option<Symbol>
Inserts or replaces a symbol in-place.
Sourcepub fn update_symbol<R>(
&mut self,
id: &SymbolId,
f: impl FnOnce(&mut Symbol) -> R,
) -> Option<R>
pub fn update_symbol<R>( &mut self, id: &SymbolId, f: impl FnOnce(&mut Symbol) -> R, ) -> Option<R>
Updates a symbol in-place.
Sourcepub fn remove_symbol(&mut self, id: &SymbolId) -> Option<Symbol>
pub fn remove_symbol(&mut self, id: &SymbolId) -> Option<Symbol>
Removes a symbol in-place.
Sourcepub fn clear_symbols(&mut self)
pub fn clear_symbols(&mut self)
Clears symbols in-place.
Sourcepub fn retain_symbols(&mut self, f: impl FnMut(&SymbolId, &mut Symbol) -> bool)
pub fn retain_symbols(&mut self, f: impl FnMut(&SymbolId, &mut Symbol) -> bool)
Retains symbols matching f.
Sourcepub fn insert_node(&mut self, id: NodeId, node: Node) -> Option<Node>
pub fn insert_node(&mut self, id: NodeId, node: Node) -> Option<Node>
Inserts or replaces a node in-place.
Sourcepub fn update_node<R>(
&mut self,
id: &NodeId,
f: impl FnOnce(&mut Node) -> R,
) -> Option<R>
pub fn update_node<R>( &mut self, id: &NodeId, f: impl FnOnce(&mut Node) -> R, ) -> Option<R>
Updates a node in-place.
Sourcepub fn remove_node(&mut self, id: &NodeId) -> Option<Node>
pub fn remove_node(&mut self, id: &NodeId) -> Option<Node>
Removes a node in-place.
Sourcepub fn clear_nodes(&mut self)
pub fn clear_nodes(&mut self)
Clears nodes in-place.
Sourcepub fn retain_nodes(&mut self, f: impl FnMut(&NodeId, &mut Node) -> bool)
pub fn retain_nodes(&mut self, f: impl FnMut(&NodeId, &mut Node) -> bool)
Retains nodes matching f.
Sourcepub fn insert_port(&mut self, id: PortId, port: Port) -> Option<Port>
pub fn insert_port(&mut self, id: PortId, port: Port) -> Option<Port>
Inserts or replaces a port in-place.
Sourcepub fn update_port<R>(
&mut self,
id: &PortId,
f: impl FnOnce(&mut Port) -> R,
) -> Option<R>
pub fn update_port<R>( &mut self, id: &PortId, f: impl FnOnce(&mut Port) -> R, ) -> Option<R>
Updates a port in-place.
Sourcepub fn remove_port(&mut self, id: &PortId) -> Option<Port>
pub fn remove_port(&mut self, id: &PortId) -> Option<Port>
Removes a port in-place.
Sourcepub fn clear_ports(&mut self)
pub fn clear_ports(&mut self)
Clears ports in-place.
Sourcepub fn retain_ports(&mut self, f: impl FnMut(&PortId, &mut Port) -> bool)
pub fn retain_ports(&mut self, f: impl FnMut(&PortId, &mut Port) -> bool)
Retains ports matching f.
Sourcepub fn insert_edge(&mut self, id: EdgeId, edge: Edge) -> Option<Edge>
pub fn insert_edge(&mut self, id: EdgeId, edge: Edge) -> Option<Edge>
Inserts or replaces an edge in-place.
Sourcepub fn update_edge<R>(
&mut self,
id: &EdgeId,
f: impl FnOnce(&mut Edge) -> R,
) -> Option<R>
pub fn update_edge<R>( &mut self, id: &EdgeId, f: impl FnOnce(&mut Edge) -> R, ) -> Option<R>
Updates an edge in-place.
Sourcepub fn remove_edge(&mut self, id: &EdgeId) -> Option<Edge>
pub fn remove_edge(&mut self, id: &EdgeId) -> Option<Edge>
Removes an edge in-place.
Sourcepub fn clear_edges(&mut self)
pub fn clear_edges(&mut self)
Clears edges in-place.
Sourcepub fn retain_edges(&mut self, f: impl FnMut(&EdgeId, &mut Edge) -> bool)
pub fn retain_edges(&mut self, f: impl FnMut(&EdgeId, &mut Edge) -> bool)
Retains edges matching f.
Sourcepub fn insert_group(&mut self, id: GroupId, group: Group) -> Option<Group>
pub fn insert_group(&mut self, id: GroupId, group: Group) -> Option<Group>
Inserts or replaces a group in-place.
Sourcepub fn update_group<R>(
&mut self,
id: &GroupId,
f: impl FnOnce(&mut Group) -> R,
) -> Option<R>
pub fn update_group<R>( &mut self, id: &GroupId, f: impl FnOnce(&mut Group) -> R, ) -> Option<R>
Updates a group in-place.
Sourcepub fn remove_group(&mut self, id: &GroupId) -> Option<Group>
pub fn remove_group(&mut self, id: &GroupId) -> Option<Group>
Removes a group in-place.
Sourcepub fn clear_groups(&mut self)
pub fn clear_groups(&mut self)
Clears groups in-place.
Sourcepub fn retain_groups(&mut self, f: impl FnMut(&GroupId, &mut Group) -> bool)
pub fn retain_groups(&mut self, f: impl FnMut(&GroupId, &mut Group) -> bool)
Retains groups matching f.
Sourcepub fn insert_sticky_note(
&mut self,
id: StickyNoteId,
note: StickyNote,
) -> Option<StickyNote>
pub fn insert_sticky_note( &mut self, id: StickyNoteId, note: StickyNote, ) -> Option<StickyNote>
Inserts or replaces a sticky note in-place.
Sourcepub fn update_sticky_note<R>(
&mut self,
id: &StickyNoteId,
f: impl FnOnce(&mut StickyNote) -> R,
) -> Option<R>
pub fn update_sticky_note<R>( &mut self, id: &StickyNoteId, f: impl FnOnce(&mut StickyNote) -> R, ) -> Option<R>
Updates a sticky note in-place.
Sourcepub fn remove_sticky_note(&mut self, id: &StickyNoteId) -> Option<StickyNote>
pub fn remove_sticky_note(&mut self, id: &StickyNoteId) -> Option<StickyNote>
Removes a sticky note in-place.
Sourcepub fn clear_sticky_notes(&mut self)
pub fn clear_sticky_notes(&mut self)
Clears sticky notes in-place.
Sourcepub fn retain_sticky_notes(
&mut self,
f: impl FnMut(&StickyNoteId, &mut StickyNote) -> bool,
)
pub fn retain_sticky_notes( &mut self, f: impl FnMut(&StickyNoteId, &mut StickyNote) -> bool, )
Retains sticky notes matching f.
Sourcepub fn insert_binding(
&mut self,
id: BindingId,
binding: Binding,
) -> Option<Binding>
pub fn insert_binding( &mut self, id: BindingId, binding: Binding, ) -> Option<Binding>
Inserts or replaces a binding in-place.
Sourcepub fn update_binding<R>(
&mut self,
id: &BindingId,
f: impl FnOnce(&mut Binding) -> R,
) -> Option<R>
pub fn update_binding<R>( &mut self, id: &BindingId, f: impl FnOnce(&mut Binding) -> R, ) -> Option<R>
Updates a binding in-place.
Sourcepub fn remove_binding(&mut self, id: &BindingId) -> Option<Binding>
pub fn remove_binding(&mut self, id: &BindingId) -> Option<Binding>
Removes a binding in-place.
Sourcepub fn clear_bindings(&mut self)
pub fn clear_bindings(&mut self)
Clears bindings in-place.
Sourcepub fn retain_bindings(
&mut self,
f: impl FnMut(&BindingId, &mut Binding) -> bool,
)
pub fn retain_bindings( &mut self, f: impl FnMut(&BindingId, &mut Binding) -> bool, )
Retains bindings matching f.
Sourcepub fn build(self) -> Result<Graph, Vec<GraphValidationError>>
pub fn build(self) -> Result<Graph, Vec<GraphValidationError>>
Validates and returns the assembled graph.
Sourcepub fn build_unchecked(self) -> Graph
pub fn build_unchecked(self) -> Graph
Returns the graph without validation.
Prefer GraphBuilder::build for normal construction. This is useful for tests and
migration tooling that intentionally produce invalid graphs and then assert diagnostics.
Methods from Deref<Target = Graph>§
Sourcepub fn graph_version(&self) -> u32
pub fn graph_version(&self) -> u32
Returns the schema version.
Sourcepub fn imports(&self) -> GraphElements<'_, GraphId, GraphImport>
pub fn imports(&self) -> GraphElements<'_, GraphId, GraphImport>
Returns graph imports.
Sourcepub fn import(&self, id: &GraphId) -> Option<&GraphImport>
pub fn import(&self, id: &GraphId) -> Option<&GraphImport>
Returns one graph import.
Sourcepub fn symbols(&self) -> GraphElements<'_, SymbolId, Symbol>
pub fn symbols(&self) -> GraphElements<'_, SymbolId, Symbol>
Returns graph symbols.
Sourcepub fn nodes(&self) -> GraphElements<'_, NodeId, Node>
pub fn nodes(&self) -> GraphElements<'_, NodeId, Node>
Returns graph nodes.
Examples found in repository?
32fn main() {
33 let node_id = NodeId::from_u128(2);
34 let mut graph = Graph::new(GraphId::from_u128(1));
35
36 let mut tx = GraphTransaction::new().with_label("add source node");
37 tx.push(GraphOp::AddNode {
38 id: node_id,
39 node: make_node("demo.source", 10.0, 20.0),
40 });
41 tx.apply_to(&mut graph).expect("transaction applies");
42
43 assert_eq!(graph.nodes().len(), 1);
44 assert_eq!(
45 graph.nodes()[&node_id].kind,
46 NodeKindKey::new("demo.source")
47 );
48}Sourcepub fn ports(&self) -> GraphElements<'_, PortId, Port>
pub fn ports(&self) -> GraphElements<'_, PortId, Port>
Returns graph ports.
Sourcepub fn edges(&self) -> GraphElements<'_, EdgeId, Edge>
pub fn edges(&self) -> GraphElements<'_, EdgeId, Edge>
Returns graph edges.
Sourcepub fn groups(&self) -> GraphElements<'_, GroupId, Group>
pub fn groups(&self) -> GraphElements<'_, GroupId, Group>
Returns graph groups.
Sourcepub fn sticky_notes(&self) -> GraphElements<'_, StickyNoteId, StickyNote>
pub fn sticky_notes(&self) -> GraphElements<'_, StickyNoteId, StickyNote>
Returns sticky notes.
Sourcepub fn sticky_note(&self, id: &StickyNoteId) -> Option<&StickyNote>
pub fn sticky_note(&self, id: &StickyNoteId) -> Option<&StickyNote>
Returns one sticky note.
Sourcepub fn bindings(&self) -> GraphElements<'_, BindingId, Binding>
pub fn bindings(&self) -> GraphElements<'_, BindingId, Binding>
Returns bindings.
Trait Implementations§
Source§impl AsRef<Graph> for GraphBuilder
impl AsRef<Graph> for GraphBuilder
Source§impl Clone for GraphBuilder
impl Clone for GraphBuilder
Source§fn clone(&self) -> GraphBuilder
fn clone(&self) -> GraphBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more