Struct gdl::graph::Graph[][src]

pub struct Graph { /* fields omitted */ }

Implementations

impl Graph[src]

pub fn append(&mut self, input: &str) -> Result<(), GraphHandlerError>[src]

Parses the given GDL string and updates the graph state.

Example

use gdl::Graph;

let mut graph = "(alice),(bob)".parse::<gdl::Graph>().unwrap();

graph.append("(alice)-[:KNOWS]->(bob)");
graph.append("(bob)-[:KNOWS]->(eve)");

assert_eq!(graph.node_count(), 3);
assert_eq!(graph.relationship_count(), 2);

pub fn node_count(&self) -> usize[src]

Returns the number of nodes in the graph.

Example

use gdl::Graph;

let graph = "()-->()-->()-->()".parse::<gdl::Graph>().unwrap();

assert_eq!(graph.node_count(), 4);

pub fn relationship_count(&self) -> usize[src]

Returns the number of relationships in the graph.

Example

use gdl::Graph;

let graph = "()-->()-->()-->()".parse::<gdl::Graph>().unwrap();

assert_eq!(graph.relationship_count(), 3);

pub fn get_node(&self, variable: &str) -> Option<&Node>[src]

Returns the node for the given variable.

Example:

use gdl::Graph;
use gdl::CypherValue;
use std::rc::Rc;

let graph = "(n0:A:B { foo: 42, bar: 1337 })".parse::<gdl::Graph>().unwrap();

let n0 = graph.get_node("n0").unwrap();

assert_eq!(n0.variable(), String::from("n0"));
assert_eq!(n0.labels().collect::<Vec<_>>(), vec!["A", "B"]);
assert_eq!(n0.property_value("foo").unwrap(), &CypherValue::from(42));

pub fn get_relationship(&self, variable: &str) -> Option<&Relationship>[src]

Returns the relationship for the given variable.

Example:

use gdl::Graph;
use gdl::CypherValue;
use std::rc::Rc;

let graph = "()-[r0:REL { foo: 42, bar: 13.37 }]->()".parse::<gdl::Graph>().unwrap();

let r0 = graph.get_relationship("r0").unwrap();

assert_eq!(r0.variable(), String::from("r0"));
assert_eq!(r0.rel_type(), Some("REL"));
assert_eq!(r0.property_value("bar").unwrap(), &CypherValue::from(13.37));

pub fn nodes(&self) -> impl Iterator<Item = &Node>[src]

Returns an iterator of nodes contained in the graph.

Example

use gdl::Graph;

let graph = "(a),(b),(c)".parse::<gdl::Graph>().unwrap();

for node in graph.nodes() {
    println!("{:?}", node);
}

pub fn relationships(&self) -> impl Iterator<Item = &Relationship>[src]

Returns an iterator of relationships contained in the graph.

Example

use gdl::Graph;

let graph = "(a)-->(b)-->(c)".parse::<gdl::Graph>().unwrap();

for relationship in graph.relationships() {
    println!("{:?}", relationship);
}

Trait Implementations

impl Default for Graph[src]

impl FromStr for Graph[src]

type Err = GraphHandlerError

The associated error which can be returned from parsing.

fn from_str(input: &str) -> Result<Self, Self::Err>[src]

Creates a new graph from the given GDL string.

Example

use gdl::Graph;
use gdl::CypherValue;
use std::rc::Rc;

let graph =
    "(alice:Person { age: 23 }),
    (bob:Person { age: 42 }),
    (alice)-[r:KNOWS]->(bob)".parse::<gdl::Graph>().unwrap();
     

assert_eq!(graph.node_count(), 2);
assert_eq!(graph.relationship_count(), 1);

let alice = graph.get_node("alice").unwrap();

assert_eq!(alice.property_value("age"), Some(&CypherValue::from(23)));

let relationship = graph.get_relationship("r").unwrap();
assert_eq!(relationship.rel_type(), Some("KNOWS"));

Auto Trait Implementations

impl !RefUnwindSafe for Graph

impl !Send for Graph

impl !Sync for Graph

impl Unpin for Graph

impl UnwindSafe for Graph

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.