DirectedLabelGraph

Struct DirectedLabelGraph 

Source
pub struct DirectedLabelGraph<D> { /* private fields */ }
Expand description

Holds the nodes of the graph

Implementations§

Source§

impl<D> DirectedLabelGraph<D>

Source

pub fn new() -> Self

Examples found in repository?
examples/make_graph.rs (line 7)
6fn main() {
7    let mut g = DirectedLabelGraph::new();
8
9    let n1 = NodeData(2);
10    let n2 = NodeData(3);
11    let n3 = NodeData(4);
12
13    g.create_node("n1", n1);
14    g.create_node("n2", n2);
15    g.create_node("n3", n3);
16
17    println!("linking: n1 -> n2\n");
18    g.link_nodes("n1", "n2", 1);
19
20    println!(
21        "n1's data before being modified: {:?}",
22        g.get_node_data("n1")
23    );
24    {
25        // modify n1's data
26        let n1_data = g.get_mut_node_data("n1").unwrap();
27        n1_data.0 = 100;
28    }
29    println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31    println!("Iter through node label and data:");
32    for nd in g.iter_node_label_and_data() {
33        println!("node data -> {:?}", nd)
34    }
35    println!();
36
37    println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38    println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}
Source

pub fn check_node_exists(&self, node_label: &str) -> bool

Source

pub fn create_node(&mut self, node_label: &str, node_data: D)

Examples found in repository?
examples/make_graph.rs (line 13)
6fn main() {
7    let mut g = DirectedLabelGraph::new();
8
9    let n1 = NodeData(2);
10    let n2 = NodeData(3);
11    let n3 = NodeData(4);
12
13    g.create_node("n1", n1);
14    g.create_node("n2", n2);
15    g.create_node("n3", n3);
16
17    println!("linking: n1 -> n2\n");
18    g.link_nodes("n1", "n2", 1);
19
20    println!(
21        "n1's data before being modified: {:?}",
22        g.get_node_data("n1")
23    );
24    {
25        // modify n1's data
26        let n1_data = g.get_mut_node_data("n1").unwrap();
27        n1_data.0 = 100;
28    }
29    println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31    println!("Iter through node label and data:");
32    for nd in g.iter_node_label_and_data() {
33        println!("node data -> {:?}", nd)
34    }
35    println!();
36
37    println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38    println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}
Source

pub fn get_node_data(&self, node_label: &str) -> Option<&D>

Examples found in repository?
examples/make_graph.rs (line 22)
6fn main() {
7    let mut g = DirectedLabelGraph::new();
8
9    let n1 = NodeData(2);
10    let n2 = NodeData(3);
11    let n3 = NodeData(4);
12
13    g.create_node("n1", n1);
14    g.create_node("n2", n2);
15    g.create_node("n3", n3);
16
17    println!("linking: n1 -> n2\n");
18    g.link_nodes("n1", "n2", 1);
19
20    println!(
21        "n1's data before being modified: {:?}",
22        g.get_node_data("n1")
23    );
24    {
25        // modify n1's data
26        let n1_data = g.get_mut_node_data("n1").unwrap();
27        n1_data.0 = 100;
28    }
29    println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31    println!("Iter through node label and data:");
32    for nd in g.iter_node_label_and_data() {
33        println!("node data -> {:?}", nd)
34    }
35    println!();
36
37    println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38    println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}
Source

pub fn get_mut_node_data(&mut self, node_label: &str) -> Option<&mut D>

Examples found in repository?
examples/make_graph.rs (line 26)
6fn main() {
7    let mut g = DirectedLabelGraph::new();
8
9    let n1 = NodeData(2);
10    let n2 = NodeData(3);
11    let n3 = NodeData(4);
12
13    g.create_node("n1", n1);
14    g.create_node("n2", n2);
15    g.create_node("n3", n3);
16
17    println!("linking: n1 -> n2\n");
18    g.link_nodes("n1", "n2", 1);
19
20    println!(
21        "n1's data before being modified: {:?}",
22        g.get_node_data("n1")
23    );
24    {
25        // modify n1's data
26        let n1_data = g.get_mut_node_data("n1").unwrap();
27        n1_data.0 = 100;
28    }
29    println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31    println!("Iter through node label and data:");
32    for nd in g.iter_node_label_and_data() {
33        println!("node data -> {:?}", nd)
34    }
35    println!();
36
37    println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38    println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}
Examples found in repository?
examples/make_graph.rs (line 18)
6fn main() {
7    let mut g = DirectedLabelGraph::new();
8
9    let n1 = NodeData(2);
10    let n2 = NodeData(3);
11    let n3 = NodeData(4);
12
13    g.create_node("n1", n1);
14    g.create_node("n2", n2);
15    g.create_node("n3", n3);
16
17    println!("linking: n1 -> n2\n");
18    g.link_nodes("n1", "n2", 1);
19
20    println!(
21        "n1's data before being modified: {:?}",
22        g.get_node_data("n1")
23    );
24    {
25        // modify n1's data
26        let n1_data = g.get_mut_node_data("n1").unwrap();
27        n1_data.0 = 100;
28    }
29    println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31    println!("Iter through node label and data:");
32    for nd in g.iter_node_label_and_data() {
33        println!("node data -> {:?}", nd)
34    }
35    println!();
36
37    println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38    println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}
Source

pub fn get_inputs_for_node( &self, node_label: &str, ) -> Option<Vec<&LabelGraphEdge>>

Examples found in repository?
examples/make_graph.rs (line 38)
6fn main() {
7    let mut g = DirectedLabelGraph::new();
8
9    let n1 = NodeData(2);
10    let n2 = NodeData(3);
11    let n3 = NodeData(4);
12
13    g.create_node("n1", n1);
14    g.create_node("n2", n2);
15    g.create_node("n3", n3);
16
17    println!("linking: n1 -> n2\n");
18    g.link_nodes("n1", "n2", 1);
19
20    println!(
21        "n1's data before being modified: {:?}",
22        g.get_node_data("n1")
23    );
24    {
25        // modify n1's data
26        let n1_data = g.get_mut_node_data("n1").unwrap();
27        n1_data.0 = 100;
28    }
29    println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31    println!("Iter through node label and data:");
32    for nd in g.iter_node_label_and_data() {
33        println!("node data -> {:?}", nd)
34    }
35    println!();
36
37    println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38    println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}
Source

pub fn get_outputs_for_node( &self, node_label: &str, ) -> Option<Vec<&LabelGraphEdge>>

Examples found in repository?
examples/make_graph.rs (line 37)
6fn main() {
7    let mut g = DirectedLabelGraph::new();
8
9    let n1 = NodeData(2);
10    let n2 = NodeData(3);
11    let n3 = NodeData(4);
12
13    g.create_node("n1", n1);
14    g.create_node("n2", n2);
15    g.create_node("n3", n3);
16
17    println!("linking: n1 -> n2\n");
18    g.link_nodes("n1", "n2", 1);
19
20    println!(
21        "n1's data before being modified: {:?}",
22        g.get_node_data("n1")
23    );
24    {
25        // modify n1's data
26        let n1_data = g.get_mut_node_data("n1").unwrap();
27        n1_data.0 = 100;
28    }
29    println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31    println!("Iter through node label and data:");
32    for nd in g.iter_node_label_and_data() {
33        println!("node data -> {:?}", nd)
34    }
35    println!();
36
37    println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38    println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}
Source

pub fn iter_node_data(&self) -> impl Iterator<Item = &D>

Source

pub fn iter_node_label_and_data(&self) -> impl Iterator<Item = (&String, &D)>

Examples found in repository?
examples/make_graph.rs (line 32)
6fn main() {
7    let mut g = DirectedLabelGraph::new();
8
9    let n1 = NodeData(2);
10    let n2 = NodeData(3);
11    let n3 = NodeData(4);
12
13    g.create_node("n1", n1);
14    g.create_node("n2", n2);
15    g.create_node("n3", n3);
16
17    println!("linking: n1 -> n2\n");
18    g.link_nodes("n1", "n2", 1);
19
20    println!(
21        "n1's data before being modified: {:?}",
22        g.get_node_data("n1")
23    );
24    {
25        // modify n1's data
26        let n1_data = g.get_mut_node_data("n1").unwrap();
27        n1_data.0 = 100;
28    }
29    println!("n1's data after modified: {:?}\n", g.get_node_data("n1"));
30
31    println!("Iter through node label and data:");
32    for nd in g.iter_node_label_and_data() {
33        println!("node data -> {:?}", nd)
34    }
35    println!();
36
37    println!("n1 outputs to: {:?}", g.get_outputs_for_node("n1"));
38    println!("n2 take input from: {:?}", g.get_inputs_for_node("n2"));
39}

Trait Implementations§

Source§

impl<D: Debug> Debug for DirectedLabelGraph<D>

Source§

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

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

impl<D> Default for DirectedLabelGraph<D>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<D> Freeze for DirectedLabelGraph<D>

§

impl<D> RefUnwindSafe for DirectedLabelGraph<D>
where D: RefUnwindSafe,

§

impl<D> Send for DirectedLabelGraph<D>
where D: Send,

§

impl<D> Sync for DirectedLabelGraph<D>
where D: Sync,

§

impl<D> Unpin for DirectedLabelGraph<D>

§

impl<D> UnwindSafe for DirectedLabelGraph<D>
where D: RefUnwindSafe,

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> 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, 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.