pub struct Graph { /* private fields */ }
Implementations§
source§impl Graph
impl Graph
sourcepub fn append(&mut self, input: &str) -> Result<(), GraphHandlerError>
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);
sourcepub fn node_count(&self) -> usize
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);
sourcepub fn relationship_count(&self) -> usize
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);
sourcepub fn get_node(&self, variable: &str) -> Option<&Node>
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));
sourcepub fn get_relationship(&self, variable: &str) -> Option<&Relationship>
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));
sourcepub fn nodes(&self) -> impl Iterator<Item = &Node>
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);
}
sourcepub fn relationships(&self) -> impl Iterator<Item = &Relationship>
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 FromStr for Graph
impl FromStr for Graph
source§fn from_str(input: &str) -> Result<Self, Self::Err>
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
type Err = GraphHandlerError
The associated error which can be returned from parsing.