1//! This module contains the `HasGet` trait and its API trait `HasGetAPI`.
23use crate::traits::has_branches::{HasBranches, HasBranchesAPI};
45use crate::HasPathSegment;
67/// This is the trait one should implement to provide a way to get branches by their path segments.
8pub trait HasGet {
9/// Gets a branch by its path segment.
10 /// It's discouraged to use this method directly. Instead, use the `get` and `get_mut` method from the `HasGetAPI` trait.
11fn get_impl<T>(self, segment: impl Into<String>) -> Option<T>
12where Self: HasBranches<T> + Sized,
13 T: HasPathSegment
14 {
15let segment = segment.into();
16self.branches_impl2::<T>().find(|value| value.path_segment() == segment)
17 }
18}
1920impl<T> HasGet for T {}
2122/// This is an API trait for getting branches by their path segments.
23pub trait HasGetAPI<'a> {
24/// Gets a branch by its path segment.
25fn get<T>(&'a self, segment: impl Into<String>) -> Option<T>
26where &'a Self: HasGet + HasBranches<T>,
27 T: HasPathSegment + 'a
28{
29self.get_impl::<T>(segment)
30 }
31}
3233impl<'a, T> HasGetAPI<'a> for T {}
3435pub trait HasGetMut<'a> {
36/// Gets a branch by its path segment mutably.
37fn get_mut<T>(&'a mut self, segment: impl Into<String>) -> Option<T>
38where &'a mut Self: HasGet + HasBranches<T>,
39 T: HasPathSegment + 'a;
40}