Struct gdl::graph::Graph

source ·
pub struct Graph { /* private fields */ }

Implementations§

source§

impl Graph

source

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

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

pub fn node_count(&self) -> usize

Returns the number of nodes in the graph.

Example

use gdl::Graph;

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

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

pub fn relationship_count(&self) -> usize

Returns the number of relationships in the graph.

Example

use gdl::Graph;

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

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

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

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

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

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

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

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);
}
source

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

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§

source§

impl Default for Graph

source§

fn default() -> Graph

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

impl FromStr for Graph

source§

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

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

type Err = GraphHandlerError

The associated error which can be returned from parsing.

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.