graph_api_lib/walker/steps/
empty.rs

1use crate::ElementId;
2use crate::graph::Graph;
3use crate::walker::{VertexWalker, Walker};
4use std::marker::PhantomData;
5
6/// # Empty Walker
7///
8/// An empty walker that doesn't produce any elements.
9/// This is a starting point for building more complex walkers.
10///
11/// ## Visual Diagram
12///
13/// ```text
14/// [Empty] -> []
15/// ```
16///
17/// The empty walker produces no elements and has no context beyond an empty tuple.
18/// This serves as the foundation for building traversals that start with fixed elements
19/// like vertices_by_id or that pull elements from non-graph sources.
20pub struct Empty<Graph, Context> {
21    _phantom: PhantomData<Graph>,
22    context: Context,
23}
24
25impl<Graph> Default for Empty<Graph, ()> {
26    fn default() -> Self {
27        Self {
28            _phantom: PhantomData,
29            context: (),
30        }
31    }
32}
33
34impl<Graph, Context> Empty<Graph, Context> {
35    pub(crate) fn with_context(context: Context) -> Self {
36        Self {
37            _phantom: PhantomData,
38            context,
39        }
40    }
41}
42
43impl<'graph, Graph: crate::Graph, Context> Walker<'graph> for Empty<Graph, Context>
44where
45    Context: Clone + 'static,
46{
47    type Graph = Graph;
48    type Context = Context;
49
50    fn next_element(&mut self, _graph: &'graph Self::Graph) -> Option<ElementId<Self::Graph>> {
51        None
52    }
53
54    fn ctx(&self) -> &Self::Context {
55        &self.context
56    }
57
58    fn ctx_mut(&mut self) -> &mut Self::Context {
59        &mut self.context
60    }
61}
62
63impl<'graph, G: Graph, Context> VertexWalker<'graph> for Empty<G, Context>
64where
65    Context: Clone + 'static,
66{
67    fn next(&mut self, _graph: &'graph Self::Graph) -> Option<<Self::Graph as Graph>::VertexId> {
68        None
69    }
70}