pub struct Edge {
pub id: EdgeId,
pub src: NodeId,
pub dst: NodeId,
pub edge_type: Arc<str>,
pub properties: BTreeMap<PropertyKey, Value>,
}Expand description
A relationship between two nodes, with a type and optional properties.
Think of edges as the “verbs” in your graph - KNOWS, WORKS_AT, PURCHASED. Each edge connects exactly one source node to one destination node.
§Example
use grafeo_core::graph::lpg::Edge;
use grafeo_common::types::{EdgeId, NodeId};
let mut works_at = Edge::new(
EdgeId::new(1),
NodeId::new(10), // Alice
NodeId::new(20), // Acme Corp
"WORKS_AT"
);
works_at.set_property("since", 2020i64);
works_at.set_property("role", "Engineer");Fields§
§id: EdgeIdUnique identifier.
src: NodeIdSource node ID.
dst: NodeIdDestination node ID.
edge_type: Arc<str>Edge type/label.
properties: BTreeMap<PropertyKey, Value>Properties stored on this edge.
Implementations§
Source§impl Edge
impl Edge
Sourcepub fn new(
id: EdgeId,
src: NodeId,
dst: NodeId,
edge_type: impl Into<Arc<str>>,
) -> Self
pub fn new( id: EdgeId, src: NodeId, dst: NodeId, edge_type: impl Into<Arc<str>>, ) -> Self
Creates a new edge.
Sourcepub fn set_property(
&mut self,
key: impl Into<PropertyKey>,
value: impl Into<Value>,
)
pub fn set_property( &mut self, key: impl Into<PropertyKey>, value: impl Into<Value>, )
Sets a property on this edge.
Sourcepub fn get_property(&self, key: &str) -> Option<&Value>
pub fn get_property(&self, key: &str) -> Option<&Value>
Gets a property from this edge.
Sourcepub fn remove_property(&mut self, key: &str) -> Option<Value>
pub fn remove_property(&mut self, key: &str) -> Option<Value>
Removes a property from this edge.
Sourcepub fn other_endpoint(&self, node: NodeId) -> Option<NodeId>
pub fn other_endpoint(&self, node: NodeId) -> Option<NodeId>
Given one endpoint, returns the other end of this edge.
Handy in traversals when you have a node and edge but need the neighbor.
Returns None if node isn’t connected to this edge.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Edge
impl RefUnwindSafe for Edge
impl Send for Edge
impl Sync for Edge
impl Unpin for Edge
impl UnwindSafe for Edge
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