use crate::Tree;
impl<'repo> Tree<'repo> {
pub fn traverse(&self) -> Platform<'_, 'repo> {
Platform {
root: self,
breadthfirst: BreadthFirstPresets { root: self },
}
}
}
pub struct Platform<'a, 'repo> {
root: &'a Tree<'repo>,
pub breadthfirst: BreadthFirstPresets<'a, 'repo>,
}
#[derive(Copy, Clone)]
pub struct BreadthFirstPresets<'a, 'repo> {
root: &'a Tree<'repo>,
}
impl BreadthFirstPresets<'_, '_> {
pub fn files(&self) -> Result<Vec<gix_traverse::tree::recorder::Entry>, gix_traverse::tree::breadthfirst::Error> {
let mut recorder = gix_traverse::tree::Recorder::default();
Platform {
root: self.root,
breadthfirst: *self,
}
.breadthfirst(&mut recorder)?;
Ok(recorder.records)
}
}
impl Platform<'_, '_> {
pub fn breadthfirst<V>(&self, delegate: &mut V) -> Result<(), gix_traverse::tree::breadthfirst::Error>
where
V: gix_traverse::tree::Visit,
{
let root = gix_object::TreeRefIter::from_bytes(&self.root.data);
let state = gix_traverse::tree::breadthfirst::State::default();
gix_traverse::tree::breadthfirst(root, state, &self.root.repo.objects, delegate)
}
pub fn depthfirst<V>(&self, delegate: &mut V) -> Result<(), gix_traverse::tree::breadthfirst::Error>
where
V: gix_traverse::tree::Visit,
{
let state = gix_traverse::tree::depthfirst::State::default();
gix_traverse::tree::depthfirst(self.root.id, state, &self.root.repo.objects, delegate)
}
}