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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
use std::rc::Rc;
//--------------------------------------------------------------------------------------------------
// Type Definitions
//--------------------------------------------------------------------------------------------------
/// Represents the directory nodes along a path.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PathNodes<T> {
pub path: Vec<(Rc<T>, String)>,
pub tail: Rc<T>,
}
/// The kinds of outcome from getting a `PathNodes`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PathNodesResult<T> {
/// The complete path exists.
Complete(PathNodes<T>),
/// The path does not exist.
MissingLink(PathNodes<T>, String),
/// Encountered a node that is not a directory.
NotADirectory(PathNodes<T>, String),
}
//--------------------------------------------------------------------------------------------------
// Implementations
//--------------------------------------------------------------------------------------------------
impl<T> PathNodes<T> {
/// Returns the length of the path nodes.
///
/// # Examples
///
/// ```
/// use wnfs_common::PathNodes;
///
/// let nodes = PathNodes::<usize> {
/// path: vec![
/// (1.into(), "music".to_string()),
/// (2.into(), "rock".to_string()),
/// ],
/// tail: 3.into(),
/// };
///
/// assert_eq!(nodes.len(), 2);
/// ```
pub fn len(&self) -> usize {
self.path.len()
}
/// Checks if the path nodes are empty.
///
/// # Examples
///
/// ```
/// use wnfs_common::PathNodes;
///
/// let nodes = PathNodes::<usize> {
/// path: vec![
/// (1.into(), "music".to_string()),
/// (2.into(), "rock".to_string()),
/// ],
/// tail: 3.into(),
/// };
///
/// assert!(!nodes.is_empty());
/// ```
pub fn is_empty(&self) -> bool {
self.path.is_empty()
}
}