Skip to main content

Graph

Struct Graph 

Source
pub struct Graph<W: WireKind> {
    pub connections: Vec<Connection>,
    pub exposed_ports: IndexMap<String, ExposedPortMeta>,
    /* private fields */
}
Expand description

A directed acyclic graph of nodes connected by typed wires.

Fields§

§connections: Vec<Connection>§exposed_ports: IndexMap<String, ExposedPortMeta>

Ordered set of exposed-port entries. Insertion order is the brush-bar display order — IndexMap preserves it through every mutation and JSON/YAML round-trip. Keys come from exposed_port_key.

Implementations§

Source§

impl<W: WireKind> Graph<W>

Source

pub fn new() -> Self

Source

pub fn nodes(&self) -> &HashMap<NodeId, NodeInstance<W>>

Read-only access to the node map. The graph owns id assignment (via add_node) and the invariant that every connection references existing nodes, so external code must go through the graph’s methods to mutate the set.

Source

pub fn add_node( &mut self, type_id: impl Into<String>, ports: Vec<PortDef<W>>, params: Vec<ParamValue>, ) -> NodeId

Add a node and return its assigned id. Any input port whose registration PortDef declares .exposed() is auto-appended to exposed_ports with empty meta — preserves the “size etc. are exposed by default” affordance.

Source

pub fn remove_node(&mut self, id: NodeId) -> Result<(), GraphError>

Remove a node, all its connections, and every brush-bar entry referencing one of its ports.

Source

pub fn expose_port( &mut self, id: NodeId, port_name: &str, ) -> Result<(), GraphError>

Add a brush-bar entry for an input port, no-op if already present. The entry starts with empty meta (registration values are used as fallback at render time).

Source

pub fn unexpose_port(&mut self, id: NodeId, port_name: &str)

Drop a brush-bar entry by (node, port). Idempotent — missing entries are not an error.

Source

pub fn is_port_exposed(&self, id: NodeId, port_name: &str) -> bool

Returns true when the named input port has a live brush-bar entry.

Source

pub fn set_exposed_port_meta( &mut self, key: &str, label: String, description: String, icon: String, ) -> Result<(), GraphError>

Overwrite all three meta fields on a brush-bar entry in one call. The icon field is restricted to FontAwesome-friendly characters ([a-zA-Z0-9- ]*) — keeps the value safe to bind directly into an HTML class= attribute on the frontend without further sanitization. Out-of-shape icon strings are rejected loudly so the caller learns about the constraint rather than seeing the icon silently dropped.

Source

pub fn reorder_exposed_port( &mut self, key: &str, new_index: usize, ) -> Result<(), GraphError>

Move an exposed-port entry to position new_index. The map’s iteration order is the brush-bar display order, so this is how drag-reorder is realised. new_index is clamped to the map’s length.

Source

pub fn connect(&mut self, from: PortRef, to: PortRef) -> Result<(), GraphError>

Connect an output port to an input port, checking types and cycles.

Source

pub fn disconnect(&mut self, from: &PortRef, to: &PortRef)

Disconnect a specific wire.

Source

pub fn inputs_for(&self, node_id: NodeId) -> impl Iterator<Item = &Connection>

All connections whose destination is a port on node_id.

Source

pub fn outputs_for(&self, node_id: NodeId) -> impl Iterator<Item = &Connection>

All connections whose source is a port on node_id.

Source

pub fn set_port_default( &mut self, id: NodeId, port_name: &str, value: f32, ) -> Result<(), GraphError>

Update a port’s default value on a node instance.

This changes the value used when the port is disconnected.

Source

pub fn set_param( &mut self, id: NodeId, index: usize, value: ParamValue, ) -> Result<(), GraphError>

Update a single parameter value on a node.

Source

pub fn find_terminal( &self, registry: &HashMap<String, NodeRegistration<W>>, ) -> Result<NodeId, FindTerminalError>

Find the unique node in this graph whose registration declares is_terminal: true. By today’s invariant a brush graph contains exactly one terminal; deviations are reported via FindTerminalError rather than silently arbitrated.

Source§

impl<W: WireKind> Graph<W>

Source

pub fn auto_layout(&self) -> NodeLayout

Compute positions for all nodes using a layered layout.

Data flows left-to-right: source nodes at x=0, downstream nodes at increasing x. Nodes within a layer are spaced vertically and ordered to minimize edge crossings.

When no measured sizes are available (tests, freshly loaded brushes), falls back to port-count-based height estimation.

Positions are not stored on the graph — the returned map is the authoritative result and callers (currently the frontend node editor) keep it as UI-only state.

Source

pub fn auto_layout_with_sizes( &self, sizes: &HashMap<NodeId, [f32; 2]>, ) -> NodeLayout

Like [auto_layout], but uses measured [width, height] from the DOM for any node present in sizes. Nodes not in the map fall back to port-count estimation.

Trait Implementations§

Source§

impl<W: Clone + WireKind> Clone for Graph<W>

Source§

fn clone(&self) -> Graph<W>

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<W: Debug + WireKind> Debug for Graph<W>

Source§

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

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

impl<W: WireKind> Default for Graph<W>

Source§

fn default() -> Self

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

impl<'de, W: WireKind> Deserialize<'de> for Graph<W>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<W: WireKind> Serialize for Graph<W>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Graph<W>

§

impl<W> RefUnwindSafe for Graph<W>
where W: RefUnwindSafe,

§

impl<W> Send for Graph<W>
where W: Send,

§

impl<W> Sync for Graph<W>
where W: Sync,

§

impl<W> Unpin for Graph<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for Graph<W>

§

impl<W> UnwindSafe for Graph<W>
where W: UnwindSafe,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,