x_bow/
path_impl.rs

1use crate::{hash_visitor::HashVisitor, path::Path, wakers::StoreWakers, PathExtGuaranteed};
2use std::cell::{Ref, RefCell, RefMut};
3
4impl<'t, T> Path for std::rc::Rc<dyn Path<Out = T> + 't> {
5    type Out = T;
6
7    fn path_borrow(&self) -> Option<Ref<'_, Self::Out>> {
8        (**self).path_borrow()
9    }
10
11    fn path_borrow_mut(&self) -> Option<RefMut<'_, Self::Out>> {
12        (**self).path_borrow_mut()
13    }
14
15    fn visit_hashes(&self, visitor: &mut HashVisitor) {
16        (**self).visit_hashes(visitor)
17    }
18
19    fn store_wakers(&self) -> &RefCell<StoreWakers> {
20        (**self).store_wakers()
21    }
22}
23
24impl<'t, T> Path for Box<dyn Path<Out = T> + 't> {
25    type Out = T;
26
27    fn path_borrow(&self) -> Option<Ref<'_, Self::Out>> {
28        (**self).path_borrow()
29    }
30
31    fn path_borrow_mut(&self) -> Option<RefMut<'_, Self::Out>> {
32        (**self).path_borrow_mut()
33    }
34
35    fn visit_hashes(&self, visitor: &mut HashVisitor) {
36        (**self).visit_hashes(visitor)
37    }
38
39    fn store_wakers(&self) -> &RefCell<StoreWakers> {
40        (**self).store_wakers()
41    }
42}
43
44/// A [Path] that is made from borrowing an owned path.
45///
46/// See [as_ref_path][crate::PathExt::as_ref_path].
47pub struct ReferencePath<'r, P: Path + ?Sized>(&'r P);
48
49impl<'r, P: Path + ?Sized> ReferencePath<'r, P> {
50    pub(crate) fn new(path: &'r P) -> Self {
51        Self(path)
52    }
53}
54
55impl<'r, P: Path + ?Sized> Clone for ReferencePath<'r, P> {
56    fn clone(&self) -> Self {
57        Self(self.0)
58    }
59}
60
61impl<'r, P: Path + ?Sized> Copy for ReferencePath<'r, P> {}
62
63impl<'r, P: Path + ?Sized> Path for ReferencePath<'r, P> {
64    type Out = P::Out;
65
66    fn path_borrow(&self) -> Option<Ref<'_, Self::Out>> {
67        self.0.path_borrow()
68    }
69    fn path_borrow_mut(&self) -> Option<RefMut<'_, Self::Out>> {
70        self.0.path_borrow_mut()
71    }
72    fn visit_hashes(&self, visitor: &mut HashVisitor) {
73        self.0.visit_hashes(visitor)
74    }
75    fn store_wakers(&self) -> &RefCell<StoreWakers> {
76        self.0.store_wakers()
77    }
78}
79
80impl<'r, P: PathExtGuaranteed + ?Sized> PathExtGuaranteed for ReferencePath<'r, P> {}