x_bow/trackable.rs
1use std::ops::Deref;
2
3use crate::path::Path;
4
5/// Allow building [Path]s into parts of this data type.
6///
7/// Use `#[derive(Trackable)]` on structs or enums to implement this.
8pub trait Trackable {
9 /// A `PathBuilder` object contains in itself a [Path] pointing to `T`.
10 /// It has methods that let you "extend" that path to point to a smaller part
11 /// of `T`: a field (if `T` is a struct), an entry (if `T` is a HashMap), etc.
12 type PathBuilder<P: Path<Out = Self>>: Deref<Target = P> + IntoPath<IntoPath = P>;
13
14 #[doc(hidden)]
15 fn new_path_builder<P: Path<Out = Self>>(parent: P) -> Self::PathBuilder<P>;
16}
17
18/// For converting a [PathBuilder][Trackable::PathBuilder] into the [Path] inside it.
19pub trait IntoPath {
20 type IntoPath;
21 /// Get the Path inside the PathBuilder.
22 fn into_path(self) -> Self::IntoPath;
23}