Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

The static topology of a flow-based network.

A Graph defines the structure of a network: which nodes exist, how they’re connected, and what conditions govern packet flow. The graph is immutable after creation.

§Example

use netrun_sim::graph::{Graph, Node, Edge, EdgeRef, PortRef, PortType, Port, PortSlotSpec};
use std::collections::HashMap;

// Create a simple A -> B graph
let node_a = Node {
    name: "A".to_string(),
    in_ports: HashMap::new(),
    out_ports: [("out".to_string(), Port { slots_spec: PortSlotSpec::Infinite })].into(),
    in_salvo_conditions: HashMap::new(),
    out_salvo_conditions: HashMap::new(),
};
let node_b = Node {
    name: "B".to_string(),
    in_ports: [("in".to_string(), Port { slots_spec: PortSlotSpec::Infinite })].into(),
    out_ports: HashMap::new(),
    in_salvo_conditions: HashMap::new(),
    out_salvo_conditions: HashMap::new(),
};

let edge = (
    EdgeRef {
        source: PortRef { node_name: "A".to_string(), port_type: PortType::Output, port_name: "out".to_string() },
        target: PortRef { node_name: "B".to_string(), port_type: PortType::Input, port_name: "in".to_string() },
    },
    Edge {},
);

let graph = Graph::new(vec![node_a, node_b], vec![edge]);
assert!(graph.validate().is_empty());

Implementations§

Source§

impl Graph

Source

pub fn new(nodes: Vec<Node>, edges: Vec<(EdgeRef, Edge)>) -> Self

Creates a new Graph from a list of nodes and edges.

Builds internal indexes for efficient edge lookups by source (tail) and target (head) ports.

Source

pub fn nodes(&self) -> &HashMap<NodeName, Node>

Returns a reference to all nodes in the graph, keyed by name.

Source

pub fn edges(&self) -> &HashMap<EdgeRef, Edge>

Returns a reference to all edges in the graph, keyed by their endpoints.

Source

pub fn get_edge_by_tail(&self, output_port_ref: &PortRef) -> Option<&EdgeRef>

Returns the edge that has the given output port as its source (tail).

Source

pub fn get_edge_by_head(&self, input_port_ref: &PortRef) -> Option<&EdgeRef>

Returns the edge that has the given input port as its target (head).

Source

pub fn validate(&self) -> Vec<GraphValidationError>

Validates the graph structure.

Returns a list of all validation errors found. An empty list means the graph is valid.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

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

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

impl<'de> Deserialize<'de> for Graph

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 Serialize for Graph

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 Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnwindSafe for Graph

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<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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,