rodo_lib 0.1.2

A Library for a Todo Manager
Documentation
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use uuid::Uuid;

use crate::utils::RodoStruct;

pub enum FIELDS {
    TITLE(String),
    ICON(String),
    DESCRIPTION(String),
    WORKING(bool),
    COLOR(u32),
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone, Debug)]
/// Struct representing a State of a Todo
///
/// * `title`: the title of the State
/// * `icon`: the icon of the State
/// * `description`: the description of the State
/// * `working`: if the State should mark a Todo as in Work
/// * `color`: the color of the State
pub struct State {
    title: String,
    icon: String,
    description: String,
    working: bool,
    color: u32,
}

impl State {
    pub fn new(
        title: &str,
        icon: &str,
        description: &str,
        working: bool,
        color: u32,
    ) -> (Uuid, Self) {
        (
            Uuid::new_v4(),
            Self {
                title: String::from(title),
                icon: String::from(icon),
                description: String::from(description),
                working,
                color,
            },
        )
    }
}

impl RodoStruct<FIELDS> for State {
    fn edit(&mut self, fields: FIELDS) {
        match fields {
            FIELDS::TITLE(t) => self.title = t,
            FIELDS::ICON(i) => self.icon = i,
            FIELDS::DESCRIPTION(d) => self.description = d,
            FIELDS::WORKING(w) => self.working = w,
            FIELDS::COLOR(c) => self.color = c,
        }
    }
}