x_bow/impls/stdlib/
boxed.rs1use std::ops::Deref;
2
3use crate::{
4 impls::{leaf::LeafPathBuilder, transparent::TransparentDerefMapper},
5 path::Path,
6 trackable::Trackable,
7};
8
9impl<T: Trackable + ?Sized> Trackable for Box<T> {
10 type PathBuilder<P: Path<Out = Self>> = BoxPathBuilder<T, P>;
11
12 fn new_path_builder<P: Path<Out = Self>>(parent: P) -> Self::PathBuilder<P> {
13 BoxPathBuilder { inner_path: parent }
14 }
15}
16
17#[derive(x_bow_macros::IntoPath)]
18#[into_path(prefix = crate::trackable)]
19pub struct BoxPathBuilder<T: ?Sized, P: Path<Out = Box<T>>> {
20 inner_path: P,
21}
22
23impl<T: ?Sized, P: Path<Out = Box<T>>> Deref for BoxPathBuilder<T, P> {
24 type Target = P;
25
26 fn deref(&self) -> &Self::Target {
27 &self.inner_path
28 }
29}
30
31impl<T: ?Sized, P: Path<Out = Box<T>> + Clone> Clone for BoxPathBuilder<T, P> {
32 fn clone(&self) -> Self {
33 Self {
34 inner_path: self.inner_path.clone(),
35 }
36 }
37}
38
39impl<T: ?Sized, P: Path<Out = Box<T>> + Copy> Copy for BoxPathBuilder<T, P> {}
40
41impl<T: Trackable + ?Sized, P: Path<Out = Box<T>>> BoxPathBuilder<T, P> {
42 pub fn content(self) -> T::PathBuilder<TransparentDerefMapper<Box<T>, P>> {
43 T::new_path_builder(TransparentDerefMapper::new(self.inner_path))
44 }
45 pub fn content_shallow(self) -> LeafPathBuilder<TransparentDerefMapper<Box<T>, P>> {
46 LeafPathBuilder::new(TransparentDerefMapper::new(self.inner_path))
47 }
48}