use pyo3::prelude::*;
#[pyclass(name = "TraversalResult")]
#[derive(Debug, Clone)]
pub struct PyTraversalResult {
#[pyo3(get)]
pub node_id: i64,
#[pyo3(get)]
pub depth: u32,
#[pyo3(get)]
pub edge_src: Option<i64>,
#[pyo3(get)]
pub edge_dst: Option<i64>,
#[pyo3(get)]
pub edge_type: Option<u32>,
}
#[pymethods]
impl PyTraversalResult {
fn __repr__(&self) -> String {
format!(
"TraversalResult(node_id={}, depth={})",
self.node_id, self.depth
)
}
}
#[pyclass(name = "PathResult")]
#[derive(Debug, Clone)]
pub struct PyPathResult {
#[pyo3(get)]
pub path: Vec<i64>,
#[pyo3(get)]
pub edges: Vec<PyPathEdge>,
#[pyo3(get)]
pub total_weight: f64,
#[pyo3(get)]
pub found: bool,
}
#[pymethods]
impl PyPathResult {
fn __repr__(&self) -> String {
if self.found {
format!(
"PathResult(path={:?}, total_weight={:.2})",
self.path, self.total_weight
)
} else {
"PathResult(found=False)".to_string()
}
}
fn __len__(&self) -> usize {
self.path.len()
}
fn __bool__(&self) -> bool {
self.found
}
}
#[pyclass(name = "PathEdge")]
#[derive(Debug, Clone)]
pub struct PyPathEdge {
#[pyo3(get)]
pub src: i64,
#[pyo3(get)]
pub etype: u32,
#[pyo3(get)]
pub dst: i64,
}
#[pymethods]
impl PyPathEdge {
fn __repr__(&self) -> String {
format!("PathEdge({} --[{}]--> {})", self.src, self.etype, self.dst)
}
}