pub struct Node { /* private fields */ }Implementations§
Source§impl Node
impl Node
Sourcepub fn from(
payload: Option<Vec<(&'static str, &'static str)>>,
node_links: Option<Vec<(&'static str, Node)>>,
) -> Self
pub fn from( payload: Option<Vec<(&'static str, &'static str)>>, node_links: Option<Vec<(&'static str, Node)>>, ) -> Self
Construct Node from payload & link vectors
§Example
use pretty_graph::Node;
let node_1 = Node::from(None, None); // Params are optional
let node_2 = Node::from(
Some(vec![
("key1", "value1"),
("key2", "value2")
]),
Some(vec![
("node_1", node_1.clone())
])
);Source§impl Node
impl Node
Sourcepub fn get(&self, k: &str) -> Option<String>
pub fn get(&self, k: &str) -> Option<String>
Get node value
§Example
use pretty_graph::Node;
let node = Node::new();
node.set("key", "value");
let v = node.get("key");Source§impl Node
impl Node
Sourcepub fn link(&self, link_as: &str, node: Node)
pub fn link(&self, link_as: &str, node: Node)
Link one node to another
§Example
use pretty_graph::Node;
let node_1 = Node::new();
let node_2 = Node::new();
node_2.link("node_1", node_1);Sourcepub fn unlink(&self, k: &str)
pub fn unlink(&self, k: &str)
Unlink one node from another
§Example
use pretty_graph::Node;
let node_1 = Node::new();
let node_2 = Node::new();
node_2.unlink("node_1");Sourcepub fn link_keys(&self) -> Vec<String>
pub fn link_keys(&self) -> Vec<String>
Get linked node keys
§Example
use pretty_graph::Node;
let node_3 = Node::new();
let node_2 = Node::new();
let node_1 = Node::new();
node_1.link("node_2", node_2);
node_1.link("node_3", node_3);
for k in node_1.link_keys() {
// ...
}Sourcepub fn node_by_key(&self, k: &str) -> Option<Node>
pub fn node_by_key(&self, k: &str) -> Option<Node>
Get to node by link chane
§Example
use pretty_graph::Node;
let node_1 = Node::from(None, None);
let node_2 = Node::from(
None,
Some(vec![
("node_1", node_1.clone())
])
);
let node_1: Option<Node> = node_2.node_by_key("node_1");Sourcepub fn node_by_chain(&self, route: Vec<&str>) -> Option<Node>
pub fn node_by_chain(&self, route: Vec<&str>) -> Option<Node>
Get to node by link chane
§Example
use pretty_graph::Node;
let node_1 = Node::from(None, None);
let node_2 = Node::from(
None,
Some(vec![
("node_1", node_1.clone())
])
);
let node_3 = Node::from(
None,
Some(vec![
("node_2", node_2.clone())
])
);
let node_1: Option<Node> = node_3.node_by_chain(vec!["node_2", "node_1"]);Source§impl Node
impl Node
Sourcepub fn pop_string(&self) -> Option<String>
pub fn pop_string(&self) -> Option<String>
Pop string from vector node
§Example
use pretty_graph::Node;
let node = Node::new_vec();
node.push_str("value");
let s = node.pop_string();Sourcepub fn get_string_by_index(&self, i: usize) -> Option<String>
pub fn get_string_by_index(&self, i: usize) -> Option<String>
Get node value
§Example
use pretty_graph::Node;
let node = Node::new_vec();
node.push_str("value");
let v = node.get_string_by_index(0);Sourcepub fn remove_string_by_index(&self, i: usize) -> String
pub fn remove_string_by_index(&self, i: usize) -> String
Remove node value
§Example
use pretty_graph::Node;
let node = Node::new_vec();
node.push_str("value");
let v = node.remove_string_by_index(0);Source§impl Node
impl Node
Sourcepub fn node_by_index(&self, i: usize) -> Option<Node>
pub fn node_by_index(&self, i: usize) -> Option<Node>
Get node by index
§Example
use pretty_graph::Node;
let node_1 = Node::new_vec();
let node_2 = Node::new();
node_1.push_node(node_2);
let node_2 = node_1.node_by_index(0);Sourcepub fn push_node(&self, node: Node)
pub fn push_node(&self, node: Node)
Push node to vector node
§Example
use pretty_graph::Node;
let node_1 = Node::new_vec();
let node_2 = Node::new();
node_1.push_node(node_2);Sourcepub fn pop_node(&self) -> Option<Node>
pub fn pop_node(&self) -> Option<Node>
Pop node from vector node
§Example
use pretty_graph::Node;
let node_1 = Node::new_vec();
let node_2 = Node::new();
node_1.push_node(node_2);
let node_2 = node_1.pop_node();Sourcepub fn remove_by_node_by_index(&self, i: usize) -> Node
pub fn remove_by_node_by_index(&self, i: usize) -> Node
Remove node by index from vector node
§Example
use pretty_graph::Node;
let node_1 = Node::new_vec();
let node_2 = Node::new();
node_1.push_node(node_2);
let node_2 = node_1.remove_by_node_by_index(0);Source§impl Node
impl Node
Sourcepub fn linked_nodes(&self) -> Vec<Node>
pub fn linked_nodes(&self) -> Vec<Node>
Get linked nodes
§Example
use pretty_graph::Node;
let node_3 = Node::new();
let node_2 = Node::new();
let node_1 = Node::new();
node_1.link("node_2", node_2);
node_1.link("node_3", node_3);
for k in node_1.linked_nodes() {
// ...
}Source§impl Node
impl Node
Sourcepub fn values(&self) -> Vec<String>
pub fn values(&self) -> Vec<String>
Get payload values
§Example
use pretty_graph::Node;
let node = Node::new();
node.set("key1", "value1");
node.set("key2", "value2");
let values = vec!["value1", "value2"];
for v in node.values().iter() {
assert!(values.contains(&v.as_str()));
}Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get payload len
§Example
use pretty_graph::Node;
let node = Node::new_vec();
node.push_str("Hi!");
println!("len: {}", node.len());
let node = Node::new();
node.set("msg", "Hi!");
println!("len: {}", node.len());
Sourcepub fn contains_string(&self, v: &String) -> bool
pub fn contains_string(&self, v: &String) -> bool
Check if vector node contains string
§Example
use pretty_graph::Node;
let node = Node::new();
node.set("key", "value");
let v = node.contains_string(&"value".to_string());
let node = Node::new_vec();
node.push_str("value");
let v = node.contains_string(&"value".to_string());Trait Implementations§
Auto Trait Implementations§
impl Freeze for Node
impl RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl UnsafeUnpin for Node
impl UnwindSafe for Node
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more