is_tree/traits/
has_branches.rs1pub trait HasBranches<T> {
5 fn branches_impl(self) -> impl Iterator<Item = T>;
8}
9
10pub trait HasBranchesAPI {
11 fn branches_impl2<T>(self) -> impl Iterator<Item = T>
13 where Self: HasBranches<T> + Sized
14 {
15 self.branches_impl()
16 }
17}
18
19impl<T> HasBranchesAPI for T {}
20
21pub trait HasBranchesAPIV2<'a> {
23 fn branches<T>(&'a self) -> impl Iterator<Item = T>
25 where &'a Self: HasBranches<T>,
26 T: 'a
27 {
28 self.branches_impl()
29 }
30
31 fn branches_mut<T>(&'a mut self) -> impl Iterator<Item = T>
33 where &'a mut Self: HasBranches<T>,
34 T: 'a
35 {
36 self.branches_impl()
37 }
38
39 fn all_branches<T>(&'a self) -> impl Iterator<Item = T>
40 where &'a Self: HasBranches<T>,
41 T: 'a + HasBranches<T> + Copy
42 {
43 self.branches_impl().flat_map(|branch| std::iter::once(branch).chain(branch.branches_impl()))
44 }
45
46 fn all_branches_mut<T>(&'a mut self) -> impl Iterator<Item = T>
47 where &'a mut Self: HasBranches<T>,
48 T: 'a + HasBranches<T> + Copy
49 {
50 self.branches_impl().flat_map(|branch| std::iter::once(branch).chain(branch.branches_impl()))
51 }
52}
53
54impl<'a, T> HasBranchesAPIV2<'a> for T {}
55
56pub trait AddBranch<T> {
58 fn add_branch(&mut self, value: T) -> &mut T;
60}