LinkView

Trait LinkView 

Source
pub trait LinkView: PortView {
    type LinkEndpoint: Into<PortIndex> + Copy;

Show 14 methods // Required methods fn get_connections( &self, from: NodeIndex, to: NodeIndex, ) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone; fn port_links( &self, port: PortIndex, ) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone; fn links( &self, node: NodeIndex, direction: Direction, ) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone; fn all_links( &self, node: NodeIndex, ) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone; fn neighbours( &self, node: NodeIndex, direction: Direction, ) -> impl Iterator<Item = NodeIndex> + Clone; fn all_neighbours( &self, node: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone; fn link_count(&self) -> usize; // Provided methods fn get_connection( &self, from: NodeIndex, to: NodeIndex, ) -> Option<(Self::LinkEndpoint, Self::LinkEndpoint)> { ... } fn connected(&self, from: NodeIndex, to: NodeIndex) -> bool { ... } fn port_link(&self, port: PortIndex) -> Option<Self::LinkEndpoint> { ... } fn input_links( &self, node: NodeIndex, ) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone { ... } fn output_links( &self, node: NodeIndex, ) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone { ... } fn input_neighbours( &self, node: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone { ... } fn output_neighbours( &self, node: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone { ... }
}
Expand description

Operations pertaining the adjacency of nodes in a port graph.

Required Associated Types§

Source

type LinkEndpoint: Into<PortIndex> + Copy

The identifier for the endpoints of a link.

Required Methods§

Source

fn get_connections( &self, from: NodeIndex, to: NodeIndex, ) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone

Returns an iterator over every pair of matching ports connecting from to to, i.e. in that direction.

§Example
let mut g: PortGraph = PortGraph::new();
let a = g.add_node(0, 2);
let b = g.add_node(2, 0);

g.link_nodes(a, 0, b, 0).unwrap();
g.link_nodes(a, 1, b, 1).unwrap();

let mut connections = g.get_connections(a, b);
assert_eq!(connections.next(), Some((g.output(a,0).unwrap(), g.input(b,0).unwrap())));
assert_eq!(connections.next(), Some((g.output(a,1).unwrap(), g.input(b,1).unwrap())));
assert_eq!(connections.next(), None);

Returns the port (or ports if this is a MultiView) that the given port is linked to.

Iterates over the connected links of the node in the given direction.

§Examples

let mut graph: PortGraph = PortGraph::new();

let node_a = graph.add_node(0, 2);
let node_b = graph.add_node(1, 0);

let port_a = graph.outputs(node_a).next().unwrap();
let port_b = graph.inputs(node_b).next().unwrap();

graph.link_ports(port_a, port_b).unwrap();

assert!(graph.links(node_a, Direction::Outgoing).eq([(port_a, port_b)]));
assert!(graph.links(node_b, Direction::Incoming).eq([(port_b, port_a)]));

Iterates over the connected input and output links of the node in sequence.

Source

fn neighbours( &self, node: NodeIndex, direction: Direction, ) -> impl Iterator<Item = NodeIndex> + Clone

Iterates over neighbour nodes in the given direction. May contain duplicates if the graph has multiple links between nodes.

§Examples

let mut graph: PortGraph = PortGraph::new();

let a = graph.add_node(0, 1);
let b = graph.add_node(2, 1);

graph.link_nodes(a, 0, b, 0).unwrap();
graph.link_nodes(b, 0, b, 1).unwrap();

assert!(graph.neighbours(a, Direction::Outgoing).eq([b]));
assert!(graph.neighbours(b, Direction::Incoming).eq([a,b]));
Source

fn all_neighbours( &self, node: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone

Iterates over the input and output neighbours of the node in sequence.

Returns the number of links between ports.

Provided Methods§

Source

fn get_connection( &self, from: NodeIndex, to: NodeIndex, ) -> Option<(Self::LinkEndpoint, Self::LinkEndpoint)>

Checks whether there is a directed link between the two nodes and returns the first matching pair of ports.

§Example
let mut g: PortGraph = PortGraph::new();
let a = g.add_node(0, 2);
let b = g.add_node(2, 0);

g.link_nodes(a, 0, b, 0).unwrap();
g.link_nodes(a, 1, b, 1).unwrap();

assert_eq!(g.get_connection(a, b), Some((g.output(a,0).unwrap(), g.input(b,0).unwrap())));
Source

fn connected(&self, from: NodeIndex, to: NodeIndex) -> bool

Checks whether there is a directed link between the two nodes.

§Example
let mut g: PortGraph = PortGraph::new();
let a = g.add_node(0, 2);
let b = g.add_node(2, 0);

g.link_nodes(a, 0, b, 0).unwrap();

assert!(g.connected(a, b));

Return the link to the provided port, if not connected return None. If this port has multiple connected subports, an arbitrary one is returned.

Iterates over the connected input links of the node. Shorthand for LinkView::links(Direction::Incoming).

Iterates over the connected output links of the node. Shorthand for LinkView::links(Direction::Outgoing)..

Source

fn input_neighbours( &self, node: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone

Iterates over the input neighbours of the node.

Shorthand for LinkView::neighbours(Direction::Incoming).

Source

fn output_neighbours( &self, node: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone

Iterates over the output neighbours of the node.

Shorthand for LinkView::neighbours(Direction::Outgoing).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<G: LinkView> LinkView for &G

Source§

type LinkEndpoint = <G as LinkView>::LinkEndpoint

Source§

fn get_connections( &self, from: NodeIndex, to: NodeIndex, ) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone

Source§

fn neighbours( &self, node: NodeIndex, direction: Direction, ) -> impl Iterator<Item = NodeIndex> + Clone

Source§

fn all_neighbours( &self, node: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone

Source§

impl<G: LinkView> LinkView for &mut G

Source§

type LinkEndpoint = <G as LinkView>::LinkEndpoint

Source§

fn get_connections( &self, from: NodeIndex, to: NodeIndex, ) -> impl Iterator<Item = (Self::LinkEndpoint, Self::LinkEndpoint)> + Clone

Source§

fn neighbours( &self, node: NodeIndex, direction: Direction, ) -> impl Iterator<Item = NodeIndex> + Clone

Source§

fn all_neighbours( &self, node: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone

Implementors§