1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/// Represents a path to a single view in the layout.
pub struct ViewPath {
/// List of turns to make on decision nodes when descending the view tree.
/// Simple nodes (with one fixed child) are skipped.
pub path: Vec<usize>,
}
new_default!(ViewPath);
impl ViewPath {
/// Creates a new empty path.
pub fn new() -> Self {
ViewPath { path: Vec::new() }
}
/// Creates a path from the given item.
pub fn from<T: ToPath>(path: T) -> Self {
path.to_path()
}
}
/// Generic trait for elements that can be converted into a `ViewPath`.
pub trait ToPath {
/// Creates a path from the element.
fn to_path(self) -> ViewPath;
}
impl<'a> ToPath for &'a [usize] {
fn to_path(self) -> ViewPath {
ViewPath {
path: self.to_owned(),
}
}
}