A Segment combines a relationship with its specific start and end nodes, describing the direction of traversal. This is useful for reconstructing the exact path structure.
Use the .segments() method to get an iterator of Segment<'path, N, R>. Each segment provides:
start: A reference to the node where the relationship begins in the traversal.relationship: The relationship object.end: A reference to the node where the relationship ends in the traversal.
Note that for a relationship (n1)-[r]->(n2), if the path traverses it in reverse (n2)<-[r]-(n1), the Segment::start will be n2 and Segment::end will be n1 to reflect the traversal direction.
// Iterating over segments to see directionality
for segment in path.segments() {
println!("From {:?} via {:?} to {:?}",
segment.start.id(),
segment.relationship.id(),
segment.end.id()
);
}