History

[traverse-tree] more proper docs

Sebastian Thiel committed 5 years ago

Commit f66ccd31 parent f7eb3555 files · +15 −12Browse files

Unified · Split

5 files
  1. git-traverse/src/lib.rs +1 −1
  2. git-traverse/src/tree/breadthfirst.rs +8 −7
  3. git-traverse/src/tree/mod.rs +2 −0
  4. git-traverse/src/tree/visit.rs +3 −3
  5. git-traverse/tests/tree/mod.rs +1 −1
git-traverse/src/lib.rs+1−1
@@ -5,5 +5,5 @@ · 4 unmodified lines
5/// Commit traversal5/// Commit traversal
6pub mod commit;6pub mod commit;
7 7
8///8/// Tree traversal
9pub mod tree;9pub mod tree;
git-traverse/src/tree/breadthfirst.rs+8−7
@@ -5,7 +5,7 @@ use quick_error::quick_error; · 4 unmodified lines
5use std::{borrow::BorrowMut, collections::VecDeque};5use std::{borrow::BorrowMut, collections::VecDeque};
6 6
7quick_error! {7quick_error! {
8 /// The error is part of the item returned by the [breadthfirst] function.8 /// The error is part of the item returned by the [`traverse()`] function.
9 #[derive(Debug)]9 #[derive(Debug)]
10 #[allow(missing_docs)]10 #[allow(missing_docs)]
11 pub enum Error {11 pub enum Error {
@@ -37,18 +37,19 @@ impl<PathId: Clone> State<PathId> { · 25 unmodified lines
37 }37 }
38}38}
39 39
40/// Create a new instance.40/// Start a breadth-first iteration over the `root` trees entries.
41///41///
42/// * `root`
43/// * the starting points of the iteration
44/// * each commit they lead to will only be returned once, including the tip that started it
45/// * `state` - all state used for the iteration. If multiple iterations are performed, allocations can be minimized by reusing
46/// this state.
42/// * `find` - a way to lookup new object data during traversal by their ObjectId, writing their data into buffer and returning47/// * `find` - a way to lookup new object data during traversal by their ObjectId, writing their data into buffer and returning
43/// an iterator over entries if the object is present and is a tree. Caching should be implemented within this function48/// an iterator over entries if the object is present and is a tree. Caching should be implemented within this function
44/// as needed. The return value is `Option<TreeIter>` which degenerates all error information. Not finding a commit should also49/// as needed. The return value is `Option<TreeIter>` which degenerates all error information. Not finding a commit should also
45/// be considered an errors as all objects in the tree DAG should be present in the database. Hence [`Error::NotFound`] should50/// be considered an errors as all objects in the tree DAG should be present in the database. Hence [`Error::NotFound`] should
46/// be escalated into a more specific error if its encountered by the caller.51/// be escalated into a more specific error if its encountered by the caller.
47/// * `state` - all state used for the iteration. If multiple iterations are performed, allocations can be minimized by reusing52/// * `delegate` - A way to observe entries and control the iteration while allowing the optimizer to let you pay only for what you use.
48/// this state.
49/// * `root`
50/// * the starting points of the iteration
51/// * each commit they lead to will only be returned once, including the tip that started it
52pub fn traverse<StateMut, Find, V>(53pub fn traverse<StateMut, Find, V>(
53 root: impl Into<ObjectId>,54 root: impl Into<ObjectId>,
54 mut state: StateMut,55 mut state: StateMut,
git-traverse/src/tree/mod.rs+2−0
@@ -8,3 +8,5 @@ pub use recorder::Recorder; · 7 unmodified lines
8 8
9///9///
10pub mod breadthfirst;10pub mod breadthfirst;
11#[doc(inline)]
12pub use breadthfirst::traverse as breadthfirst;
git-traverse/src/tree/visit.rs+3−3
@@ -1,14 +1,14 @@
1use git_hash::bstr::BStr;1use git_hash::bstr::BStr;
2use git_object::immutable;2use git_object::immutable;
3 3
4/// What to do after an entry was [recorded][Visit::visit()].4/// What to do after an entry was [recorded][Visit::visit_tree()].
5#[derive(Clone, Copy, PartialOrd, PartialEq, Ord, Eq, Hash)]5#[derive(Clone, Copy, PartialOrd, PartialEq, Ord, Eq, Hash)]
6pub enum Action {6pub enum Action {
7 /// Continue the traversal of entries.7 /// Continue the traversal of entries.
8 Continue,8 Continue,
9 /// Stop the traversal of entries, making this te last call to [visit(…)][Visit::visit()].9 /// Stop the traversal of entries, making this te last call to [`visit_(tree|nontree)(…)`][Visit::visit_nontree()].
10 Cancel,10 Cancel,
11 /// Don't dive into the entry, skipping children effectively.11 /// Don't dive into the entry, skipping children effectively. Only useful in [`visit_tree(…)`][Visit::visit_tree()].
12 Skip,12 Skip,
13}13}
14 14
git-traverse/tests/tree/mod.rs+1−1
@@ -22,7 +22,7 @@ fn basic_nesting() -> crate::Result<()> { · 21 unmodified lines
22 .into_commit_iter()22 .into_commit_iter()
23 .expect("commit present");23 .expect("commit present");
24 let mut recorder = tree::Recorder::default();24 let mut recorder = tree::Recorder::default();
25 tree::breadthfirst::traverse(25 git_traverse::tree::breadthfirst(
26 commit.tree_id().expect("a tree is available in a commit"),26 commit.tree_id().expect("a tree is available in a commit"),
27 tree::breadthfirst::State::default(),27 tree::breadthfirst::State::default(),
28 |oid, buf| {28 |oid, buf| {