pub use globbing::*;
use std::fmt::Debug;
mod globbing;
#[derive(Debug, Clone)]
pub struct File {
pub path: String,
pub data: FileData,
}
#[derive(Debug, Clone)]
pub enum FileData {
Blob(Vec<u8>),
Text(String),
}
impl FileData {
pub fn _type(&self) -> String {
match self {
Self::Blob(_) => "Vec<u8>",
Self::Text(_) => "String",
}
.to_string()
}
}
pub trait Directory {
fn files(&self) -> Vec<File>;
fn glob(&self, search: &str) -> Result<Vec<File>, globset::Error> {
glob(self.files(), search)
}
}
pub trait Data {
fn to_file_data(self) -> FileData;
}
impl Data for String {
fn to_file_data(self) -> FileData {
FileData::Text(self)
}
}
impl Data for Vec<u8> {
fn to_file_data(self) -> FileData {
FileData::Blob(self)
}
}