Skip to main content

Node

Struct Node 

Source
pub struct Node { /* private fields */ }

Implementations§

Source§

impl Node

Source

pub fn new() -> Self

Construct Node

§Example
use pretty_graph::Node;

let node = Node::new();
Source§

impl Node

Source

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

Source

pub fn set(&self, k: &str, v: &str)

Set node value

§Example
use pretty_graph::Node;

let node = Node::new();
node.set("key", "value");
Source

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

pub fn remove(&self, k: &str) -> Option<String>

Remove node value

§Example
use pretty_graph::Node;

let node = Node::new();
node.set("key", "value");
let v = node.remove("key");
Source

pub fn keys(&self) -> Vec<String>

Get payload keys

§Example
use pretty_graph::Node;

let node = Node::new();
node.set("key1", "value1");
node.set("key2", "value2");

let keys = vec!["key1", "key2"];

for k in node.keys().iter() {
   assert!(keys.contains(&k.as_str()));
}
Source§

impl 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);

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");

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() {
   // ...
}
Source

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");
Source

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

Source

pub fn new_vec() -> Self

Construct Node

§Example
use pretty_graph::Node;

let node = Node::new_vec();
Source§

impl Node

Source

pub fn vec_from( payload: Option<Vec<&str>>, node_links: Option<Vec<Node>>, ) -> Self

Construct Node from payload & link vectors

§Example
use pretty_graph::Node;

let node_1 = Node::new();
let node_2 = Node::vec_from(
    Some(vec![
        "value1",
        "value2"
    ]),
    Some(vec![
        node_1
    ])
);
Source§

impl Node

Source

pub fn push_str(&self, v: &str)

Set node value

§Example
use pretty_graph::Node;

let node = Node::new_vec();
node.push_str("value");
Source

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();
Source

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);
Source

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

Source

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);
Source

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);
Source

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();
Source

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

Source

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

Source

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()));
}
Source

pub fn clear(&self)

Clear payload

§Example
use pretty_graph::Node;

let node = Node::new();

node.clear();
Source

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());
Source

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§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

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 Node

Source§

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

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

impl Universal for Node

Source§

fn get_str_vector_by_key_or(&self, k: &str, or: Vec<&str>) -> Vec<String>

Get node by key and then trys to return its values or vector you set into or argument. Example Read more

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