hdrepresentation 0.1.8

HYDRAulic Damnation's representation of filesystem for fuzzing
Documentation
pub use crate::types::*;
pub use std::collections::HashMap;

#[derive(Serialize, Deserialize, Debug, Eq, Clone, Hash, PartialEq)]
pub struct Xattr(pub String, pub String, pub i64);

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq, Hash)]
pub struct FileObject {
    pub rel_path: String,
    pub ftype: FileType,
    pub xattrs: Vec<Xattr>,
}

impl FileObject {
    pub fn new(path: &str, ftype: FileType) -> Self {
        Self {
            rel_path: String::from(path),
            ftype,
            xattrs: Vec::<Xattr>::new(),
        }
    }
}

impl fmt::Display for FileObject {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let mut output = format!("Path {}\n Type: ", self.rel_path);
        let ftype = match self.ftype {
            FileType::Symlink => String::from("symlink"),
            FileType::File => String::from("file"),
            FileType::Dir => String::from("dir"),
            FileType::Fifo => String::from("fifo"),
            _ => String::from("other"),
        };
        output.push_str(&ftype);
        output.push_str("\nXattrs:\n");
        for xattr in self.xattrs.iter() {
            output.push_str(&format!("\t{}:{}\n", xattr.0, xattr.1));
        }
        write!(f, "{}\n", output)
    }
}