pub struct Edge {
pub id: EdgeId,
pub src: NodeId,
pub dst: NodeId,
pub edge_type: ArcStr,
pub properties: PropertyMap,
}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: ArcStrEdge type/label.
properties: PropertyMapProperties stored on this edge.
Implementations§
Source§impl Edge
impl Edge
Sourcepub fn new(
id: EdgeId,
src: NodeId,
dst: NodeId,
edge_type: impl Into<ArcStr>,
) -> Self
pub fn new( id: EdgeId, src: NodeId, dst: NodeId, edge_type: impl Into<ArcStr>, ) -> 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 properties_as_btree(&self) -> BTreeMap<PropertyKey, Value>
pub fn properties_as_btree(&self) -> BTreeMap<PropertyKey, Value>
Returns the properties as a BTreeMap (for serialization compatibility).
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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more