2015-05-16 00:56:38 +00:00
|
|
|
/// 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>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ViewPath {
|
|
|
|
/// Creates a new empty path.
|
|
|
|
pub fn new() -> Self {
|
2016-03-15 22:37:57 +00:00
|
|
|
ViewPath { path: Vec::new() }
|
2015-05-16 00:56:38 +00:00
|
|
|
}
|
2015-05-16 21:02:15 +00:00
|
|
|
|
2015-05-20 00:31:52 +00:00
|
|
|
/// Creates a path from the given item.
|
2015-05-16 21:02:15 +00:00
|
|
|
pub fn from<T: ToPath>(path: T) -> Self {
|
|
|
|
path.to_path()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-20 00:31:52 +00:00
|
|
|
/// Generic trait for elements that can be converted into a ViewPath.
|
2015-05-16 21:02:15 +00:00
|
|
|
pub trait ToPath {
|
2015-05-20 00:31:52 +00:00
|
|
|
/// Creates a path from the element.
|
2015-05-16 21:02:15 +00:00
|
|
|
fn to_path(self) -> ViewPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl <'a> ToPath for &'a [usize] {
|
|
|
|
fn to_path(self) -> ViewPath {
|
2016-03-15 22:37:57 +00:00
|
|
|
ViewPath { path: self.to_owned() }
|
2015-05-16 21:02:15 +00:00
|
|
|
}
|
2015-05-16 00:56:38 +00:00
|
|
|
}
|