/// Adds a task to the list
///
/// The new task will be inserted at the bottom of todo.txt.
/// In case of success, this function returns a tuple containing the task ID and its formatted string.
///
/// # Errors
///
/// - couldn't find nor open the file with read and write access
/// - couldn't write to the file
Adds a task to the list
The new task will be inserted at the bottom of todo.txt.
In case of success, this function returns a tuple containing the task ID and its formatted string.
Adds a task to the list The new task will be inserted at the bottom of todo . txt . In case of success this function returns a tuple containing the task ID and its formatted string .
pub fn add(
    todo: &str,
    priority: Option<char>,
    creation_date: Option<NaiveDate>,
    insert_creation_date: bool,
) -> Result<(usize, String), String> {
    let mut file = OpenOptions::new()
        .read(true)
        .append(true)
        .open(TODOTXT_PATH)
        .map_err(|e| e.to_string())?;
    let new_task = format_task(todo, priority, creation_date, insert_creation_date);
    writeln!(&file, "{}", new_task).map_err(|e| e.to_string())?;
    file.seek(SeekFrom::Start(0)).map_err(|e| e.to_string())?;
    let task_id = BufReader::new(file).lines().count();
    Ok((task_id, new_task))
}
pub fn add ( todo : & str , priority : Option < char > , creation_date : Option < NaiveDate > , insert_creation_date : bool , ) -> Result < ( usize , String ) , String > { let mut file = OpenOptions :: new ( ) . read ( true ) . append ( true ) . open ( TODOTXT_PATH ) . map_err ( | e | e . to_string ( ) ) ? ; let new_task = format_task ( todo , priority , creation_date , insert_creation_date ) ; writeln ! ( file " " new_task ) . map_err ( | e | e . to_string ( ) ) ? ; file . seek ( SeekFrom :: Start ( 0 ) ) . map_err ( | e | e . to_string ( ) ) ? ; let task_id = BufReader :: new ( file ) . lines ( ) . count ( ) ; Ok ( ( task_id , new_task ) ) }
Adds a task to the list
The new task will be inserted at the bottom of todo.txt.
Adds a task to the list The new task will be inserted at the bottom of todo . txt .
todo
&str
priority
Option<char>
creation_date
Option<NaiveDate>
insert_creation_date
bool
errors
couldn't find nor open the file with read and write access
couldn't write to the file
couldn ' t find nor open the file with read and write access couldn ' t write to the file