task_manager_command_line 0.1.1

A simple task manager cli tool
Documentation
//! Defines the data structures for the task manager, primarily the `Task` struct.

use chrono::{DateTime, NaiveDate, Utc};
use serde::{Deserialize, Serialize};

/// Represents a single task in the task manager.
///
/// Each task has a unique ID, a description, a completion status,
/// the timestamp when it was created, and an optional due date.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Task {
    pub id: u32,
    pub description: String,
    pub completed: bool,
    #[serde(with = "chrono::serde::ts_seconds")] // Serialize as Unix timestamp
    pub created_at: DateTime<Utc>,
    pub due_date: Option<NaiveDate>,
}

impl Task {
    /// Creates a new `Task` instance.
    ///
    /// The `id` should be unique and usually generated by the task manager logic.
    /// `created_at` is set to the current UTC timestamp.
    ///
    /// # Arguments
    ///
    /// * `id` - The unique identifier for the new task.
    /// * `description` - A string describing the task.
    /// * `due_date` - An optional `NaiveDate` for when the task is due.
    ///
    /// # Returns
    ///
    /// A new `Task` instance, initially marked as not completed.
    pub fn new(id: u32, description: String, due_date: Option<NaiveDate>) -> Self {
        Task {
            id,
            description,
            completed: false,
            created_at: Utc::now(),
            due_date,
        }
    }

    /// Sets the completion status of the task.
    ///
    /// # Arguments
    ///
    /// * `status` - A boolean indicating whether the task is completed (`true`)
    ///              or not completed (`false`).
    pub fn mark_completion(&mut self, status: bool) {
        self.completed = status;
    }
}

/// A wrapper struct for serializing and deserializing a list of tasks to TOML.
#[derive(Debug, Serialize, Deserialize)]
pub struct TaskList {
    pub tasks: Vec<Task>,
}

impl TaskList {
    /// Creates a new empty `TaskList`.
    pub fn new() -> Self {
        TaskList { tasks: Vec::new() }
    }
}

// Add a Default implementation for convenience
impl Default for TaskList {
    /// Creates sensible defaults to `TaskList`.
    fn default() -> Self {
        Self::new()
    }
}