cursive/cursive-core/src/view/view_path.rs

35 lines
820 B
Rust
Raw Normal View History

/// 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>,
}
2016-07-17 00:28:42 +00:00
new_default!(ViewPath);
2016-06-28 05:40:11 +00:00
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 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()
}
}
2016-06-28 05:40:11 +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;
}
2016-06-25 23:36:22 +00:00
impl<'a> ToPath for &'a [usize] {
2015-05-16 21:02:15 +00:00
fn to_path(self) -> ViewPath {
2017-10-12 23:38:55 +00:00
ViewPath {
path: self.to_owned(),
}
2015-05-16 21:02:15 +00:00
}
}