is_tree/traits/
has_get.rs1use crate::traits::has_branches::{HasBranches, HasBranchesAPI};
4
5use crate::HasPathSegment;
6
7pub trait HasGet {
9 fn get_impl<T>(self, segment: impl Into<String>) -> Option<T>
12 where Self: HasBranches<T> + Sized,
13 T: HasPathSegment
14 {
15 let segment = segment.into();
16 self.branches_impl2::<T>().find(|value| value.path_segment() == segment)
17 }
18}
19
20impl<T> HasGet for T {}
21
22pub trait HasGetAPI<'a> {
24 fn get<T>(&'a self, segment: impl Into<String>) -> Option<T>
26 where &'a Self: HasGet + HasBranches<T>,
27 T: HasPathSegment + 'a
28 {
29 self.get_impl::<T>(segment)
30 }
31}
32
33impl<'a, T> HasGetAPI<'a> for T {}
34
35pub trait HasGetMut<'a> {
36 fn get_mut<T>(&'a mut self, segment: impl Into<String>) -> Option<T>
38 where &'a mut Self: HasGet + HasBranches<T>,
39 T: HasPathSegment + 'a;
40}