pub struct Relationship {
pub from: EntityId,
pub to: EntityId,
pub kind: String,
pub weight: f32,
}Expand description
A directed, typed edge between two entities.
Fields§
§from: EntityIdSource entity.
to: EntityIdTarget entity.
kind: StringRelationship type label (e.g. “KNOWS”, “PART_OF”).
weight: f32Optional weight for weighted-graph use cases.
Implementations§
Source§impl Relationship
impl Relationship
Sourcepub fn new(
from: impl Into<String>,
to: impl Into<String>,
kind: impl Into<String>,
weight: f32,
) -> Self
pub fn new( from: impl Into<String>, to: impl Into<String>, kind: impl Into<String>, weight: f32, ) -> Self
Construct a new relationship with the given kind and weight.
Sourcepub fn is_self_loop(&self) -> bool
pub fn is_self_loop(&self) -> bool
Return true if this relationship is a self-loop (from == to).
Sourcepub fn reversed(&self) -> Self
pub fn reversed(&self) -> Self
Return a new Relationship with from and to swapped.
The kind and weight are preserved unchanged.
Sourcepub fn with_weight(self, w: f32) -> Self
pub fn with_weight(self, w: f32) -> Self
Return a copy of this relationship with the weight changed to w.
All other fields (from, to, kind) are cloned unchanged, making
this convenient for builder-style graph construction:
use llm_agent_runtime::graph::Relationship;
let rel = Relationship::new("a", "b", "KNOWS", 1.0).with_weight(0.5);
assert_eq!(rel.weight, 0.5);Trait Implementations§
Source§impl Clone for Relationship
impl Clone for Relationship
Source§fn clone(&self) -> Relationship
fn clone(&self) -> Relationship
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Relationship
impl Debug for Relationship
Source§impl<'de> Deserialize<'de> for Relationship
impl<'de> Deserialize<'de> for Relationship
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for Relationship
impl Display for Relationship
Auto Trait Implementations§
impl Freeze for Relationship
impl RefUnwindSafe for Relationship
impl Send for Relationship
impl Sync for Relationship
impl Unpin for Relationship
impl UnsafeUnpin for Relationship
impl UnwindSafe for Relationship
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