is_tree/traits/
has_branch.rs1use crate::longer_mut;
2use super::{AddBranch, HasBranches, HasGet, HasGetMut, HasPathSegment};
3
4pub trait HasBranch<'a> {
6 fn branch<T>(&'a mut self, segment: impl Into<String>) -> &'a mut T
7 where &'a mut Self: HasGet + HasBranches<&'a mut T>,
8 Self: AddBranch<T> + Sized + HasGetMut<'a>,
9 T: HasPathSegment + 'a,
10 String: Into<T>
11 {
12 let segment = segment.into();
13 let self_ = unsafe { longer_mut(self) }; if let Some(value) = self.get_mut::<&mut T>(segment.clone()) {
15 value
16 } else {
17 self_.add_branch(segment.into())
18 }
19 }
20}
21
22impl<'a, T> HasBranch<'a> for T {}