x_bow/
path.rs

1use std::cell::{Ref, RefCell, RefMut};
2
3use crate::{hash_visitor::HashVisitor, wakers::StoreWakers};
4
5/// A Path object identifies a piece of the data store.
6///
7/// It can convert a borrow of the store's data to a borrow of the piece it identifies.
8///
9/// Often, you won't be working with the `Path` trait itself, but rather
10/// the [PathExt][crate::PathExt] trait.
11///
12/// Path objects are mostly generated by `#[derive(x_bow::Trackable)]`.
13/// To hand-implement, see example code in `src/impls/stdlib`.
14pub trait Path {
15    type Out: ?Sized;
16
17    /// Borrow the data at the given path immutably.
18    ///
19    /// **Do not use this**. It is considered "internal" API. Use the equivalent
20    /// [borrow_opt_mut][crate::PathExt::borrow_opt_mut] instead.
21    ///
22    /// If there is an existing mutable borrow anywhere in the store,
23    /// this method will panic.
24    #[doc(hidden)]
25    fn path_borrow(&self) -> Option<Ref<'_, Self::Out>>;
26
27    /// Borrow the data at the given path mutably.
28    ///
29    /// **Do not use this**. It is considered "internal" API. Use the equivalent
30    /// [borrow_opt_mut_without_notifying][crate::PathExt::borrow_opt_mut_without_notifying] instead.
31    ///
32    /// If there is an existing mutable or immutable borrow anywhere in the store,
33    /// this method will panic.
34    #[doc(hidden)]
35    fn path_borrow_mut(&self) -> Option<RefMut<'_, Self::Out>>;
36
37    /// Call the given visitor function on the hash of this path node and every
38    /// ancestor node in the path.
39    #[doc(hidden)]
40    fn visit_hashes(&self, visitor: &mut HashVisitor);
41
42    /// Used internally for subscription and notification system.
43    #[doc(hidden)]
44    fn store_wakers(&self) -> &RefCell<StoreWakers>;
45}