leafslug_tsk 0.4.0

A personal Task Management System that is not inteded to be used by others... yet.
Documentation
use std::path::PathBuf;

use leafslug_effects::files::is_json;

use super::{task::Task, Error};

// #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
// #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
// pub struct TaskList(pub Vec<TaskDescription>);

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct TaskDescription {
    pub task: Task,
    pub file_name: String,
}

impl TryFrom<&PathBuf> for TaskDescription {
    type Error = Error;

    fn try_from(value: &PathBuf) -> Result<Self, Self::Error> {
        let task = Task::try_from(value)?;
        let file_name = value
            .file_name()
            .ok_or(Error::IsNotAFile)?
            .to_str()
            .ok_or(Error::FileNameHasInvalidCharacters)?
            .to_owned();
        Ok(Self { task, file_name })
    }
}
impl TryFrom<PathBuf> for TaskDescription {
    type Error = Error;

    fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
        let task = Task::try_from(&value)?;
        let file_name = value
            .file_name()
            .ok_or(Error::IsNotAFile)?
            .to_str()
            .ok_or(Error::FileNameHasInvalidCharacters)?
            .to_owned();
        Ok(Self { task, file_name })
    }
}
pub fn task_list(p: &PathBuf) -> Result<impl Iterator<Item = TaskDescription>, Error> {
    Ok(fs_extra::dir::get_dir_content(p)
        .map_err(Error::DirCouldNotBeRead)?
        .files
        .into_iter()
        .map(PathBuf::from)
        .filter(is_json)
        .flat_map(TaskDescription::try_from))
}