Skip to main content

GraphBuilder

Struct GraphBuilder 

Source
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

Source

pub fn new(graph_id: GraphId) -> Self

Creates an empty builder for the given graph id.

Source

pub fn graph_id(&self) -> GraphId

Returns the graph id being built.

Source

pub fn graph(&self) -> &Graph

Borrows the current graph snapshot.

Source

pub fn with_import(self, id: GraphId, import: GraphImport) -> Self

Adds or replaces an import.

Source

pub fn with_symbol(self, id: SymbolId, symbol: Symbol) -> Self

Adds or replaces a symbol.

Source

pub fn with_node(self, id: NodeId, node: Node) -> Self

Adds or replaces a node.

Source

pub fn with_port(self, id: PortId, port: Port) -> Self

Adds or replaces a port.

Source

pub fn with_edge(self, id: EdgeId, edge: Edge) -> Self

Adds or replaces an edge.

Source

pub fn with_group(self, id: GroupId, group: Group) -> Self

Adds or replaces a group.

Source

pub fn with_sticky_note(self, id: StickyNoteId, note: StickyNote) -> Self

Adds or replaces a sticky note.

Source

pub fn with_binding(self, id: BindingId, binding: Binding) -> Self

Adds or replaces a binding.

Source

pub fn insert_import( &mut self, id: GraphId, import: GraphImport, ) -> Option<GraphImport>

Inserts or replaces an import in-place.

Source

pub fn update_import<R>( &mut self, id: &GraphId, f: impl FnOnce(&mut GraphImport) -> R, ) -> Option<R>

Updates an import in-place.

Source

pub fn remove_import(&mut self, id: &GraphId) -> Option<GraphImport>

Removes an import in-place.

Source

pub fn clear_imports(&mut self)

Clears imports in-place.

Source

pub fn retain_imports( &mut self, f: impl FnMut(&GraphId, &mut GraphImport) -> bool, )

Retains imports matching f.

Source

pub fn insert_symbol(&mut self, id: SymbolId, symbol: Symbol) -> Option<Symbol>

Inserts or replaces a symbol in-place.

Source

pub fn update_symbol<R>( &mut self, id: &SymbolId, f: impl FnOnce(&mut Symbol) -> R, ) -> Option<R>

Updates a symbol in-place.

Source

pub fn remove_symbol(&mut self, id: &SymbolId) -> Option<Symbol>

Removes a symbol in-place.

Source

pub fn clear_symbols(&mut self)

Clears symbols in-place.

Source

pub fn retain_symbols(&mut self, f: impl FnMut(&SymbolId, &mut Symbol) -> bool)

Retains symbols matching f.

Source

pub fn insert_node(&mut self, id: NodeId, node: Node) -> Option<Node>

Inserts or replaces a node in-place.

Source

pub fn update_node<R>( &mut self, id: &NodeId, f: impl FnOnce(&mut Node) -> R, ) -> Option<R>

Updates a node in-place.

Source

pub fn remove_node(&mut self, id: &NodeId) -> Option<Node>

Removes a node in-place.

Source

pub fn clear_nodes(&mut self)

Clears nodes in-place.

Source

pub fn retain_nodes(&mut self, f: impl FnMut(&NodeId, &mut Node) -> bool)

Retains nodes matching f.

Source

pub fn insert_port(&mut self, id: PortId, port: Port) -> Option<Port>

Inserts or replaces a port in-place.

Source

pub fn update_port<R>( &mut self, id: &PortId, f: impl FnOnce(&mut Port) -> R, ) -> Option<R>

Updates a port in-place.

Source

pub fn remove_port(&mut self, id: &PortId) -> Option<Port>

Removes a port in-place.

Source

pub fn clear_ports(&mut self)

Clears ports in-place.

Source

pub fn retain_ports(&mut self, f: impl FnMut(&PortId, &mut Port) -> bool)

Retains ports matching f.

Source

pub fn insert_edge(&mut self, id: EdgeId, edge: Edge) -> Option<Edge>

Inserts or replaces an edge in-place.

Source

pub fn update_edge<R>( &mut self, id: &EdgeId, f: impl FnOnce(&mut Edge) -> R, ) -> Option<R>

Updates an edge in-place.

Source

pub fn remove_edge(&mut self, id: &EdgeId) -> Option<Edge>

Removes an edge in-place.

Source

pub fn clear_edges(&mut self)

Clears edges in-place.

Source

pub fn retain_edges(&mut self, f: impl FnMut(&EdgeId, &mut Edge) -> bool)

Retains edges matching f.

Source

pub fn insert_group(&mut self, id: GroupId, group: Group) -> Option<Group>

Inserts or replaces a group in-place.

Source

pub fn update_group<R>( &mut self, id: &GroupId, f: impl FnOnce(&mut Group) -> R, ) -> Option<R>

Updates a group in-place.

Source

pub fn remove_group(&mut self, id: &GroupId) -> Option<Group>

Removes a group in-place.

Source

pub fn clear_groups(&mut self)

Clears groups in-place.

Source

pub fn retain_groups(&mut self, f: impl FnMut(&GroupId, &mut Group) -> bool)

Retains groups matching f.

Source

pub fn insert_sticky_note( &mut self, id: StickyNoteId, note: StickyNote, ) -> Option<StickyNote>

Inserts or replaces a sticky note in-place.

Source

pub fn update_sticky_note<R>( &mut self, id: &StickyNoteId, f: impl FnOnce(&mut StickyNote) -> R, ) -> Option<R>

Updates a sticky note in-place.

Source

pub fn remove_sticky_note(&mut self, id: &StickyNoteId) -> Option<StickyNote>

Removes a sticky note in-place.

Source

pub fn clear_sticky_notes(&mut self)

Clears sticky notes in-place.

Source

pub fn retain_sticky_notes( &mut self, f: impl FnMut(&StickyNoteId, &mut StickyNote) -> bool, )

Retains sticky notes matching f.

Source

pub fn insert_binding( &mut self, id: BindingId, binding: Binding, ) -> Option<Binding>

Inserts or replaces a binding in-place.

Source

pub fn update_binding<R>( &mut self, id: &BindingId, f: impl FnOnce(&mut Binding) -> R, ) -> Option<R>

Updates a binding in-place.

Source

pub fn remove_binding(&mut self, id: &BindingId) -> Option<Binding>

Removes a binding in-place.

Source

pub fn clear_bindings(&mut self)

Clears bindings in-place.

Source

pub fn retain_bindings( &mut self, f: impl FnMut(&BindingId, &mut Binding) -> bool, )

Retains bindings matching f.

Source

pub fn build(self) -> Result<Graph, Vec<GraphValidationError>>

Validates and returns the assembled graph.

Source

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>§

Source

pub fn graph_id(&self) -> GraphId

Returns the stable graph identity.

Source

pub fn graph_version(&self) -> u32

Returns the schema version.

Source

pub fn imports(&self) -> GraphElements<'_, GraphId, GraphImport>

Returns graph imports.

Source

pub fn import(&self, id: &GraphId) -> Option<&GraphImport>

Returns one graph import.

Source

pub fn symbols(&self) -> GraphElements<'_, SymbolId, Symbol>

Returns graph symbols.

Source

pub fn symbol(&self, id: &SymbolId) -> Option<&Symbol>

Returns one symbol.

Source

pub fn nodes(&self) -> GraphElements<'_, NodeId, Node>

Returns graph nodes.

Examples found in repository?
examples/build_graph.rs (line 43)
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}
Source

pub fn node(&self, id: &NodeId) -> Option<&Node>

Returns one node.

Source

pub fn ports(&self) -> GraphElements<'_, PortId, Port>

Returns graph ports.

Source

pub fn port(&self, id: &PortId) -> Option<&Port>

Returns one port.

Source

pub fn edges(&self) -> GraphElements<'_, EdgeId, Edge>

Returns graph edges.

Source

pub fn edge(&self, id: &EdgeId) -> Option<&Edge>

Returns one edge.

Source

pub fn groups(&self) -> GraphElements<'_, GroupId, Group>

Returns graph groups.

Source

pub fn group(&self, id: &GroupId) -> Option<&Group>

Returns one group.

Source

pub fn sticky_notes(&self) -> GraphElements<'_, StickyNoteId, StickyNote>

Returns sticky notes.

Source

pub fn sticky_note(&self, id: &StickyNoteId) -> Option<&StickyNote>

Returns one sticky note.

Source

pub fn bindings(&self) -> GraphElements<'_, BindingId, Binding>

Returns bindings.

Source

pub fn binding(&self, id: &BindingId) -> Option<&Binding>

Returns one binding.

Trait Implementations§

Source§

impl AsRef<Graph> for GraphBuilder

Source§

fn as_ref(&self) -> &Graph

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for GraphBuilder

Source§

fn clone(&self) -> GraphBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GraphBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GraphBuilder

Source§

fn default() -> GraphBuilder

Returns the “default value” for a type. Read more
Source§

impl Deref for GraphBuilder

Source§

type Target = Graph

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl From<GraphBuilder> for Graph

Source§

fn from(builder: GraphBuilder) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.