Crate tdtxt[][src]

Expand description

tdtxt

A rust library for de(serializing) files and text in the todo.txt format.

Examples

use std::str::FromStr as _;

use tdtxt::{Task, Date, State, Priority, DateCompound};

let line = "x (A) 2016-05-20 2016-04-30 measure space for +chapelShelving @chapel due:2016-05-30";
let task = Task::from_str(line).unwrap();

assert_eq!(task.state(), &State::Done);
assert_eq!(task.priority(), Some(&Priority::A));
assert_eq!(task.date_compound(), Some(&DateCompound::Completed { created: Date::from_ymd(2016, 4, 30), completed: Date::from_ymd(2016, 5, 20) }));
assert_eq!(task.description().description(), "measure space for +chapelShelving @chapel due:2016-05-30");
assert_eq!(task.description().projects().collect::<Vec<_>>(), vec!["chapelShelving"]);
assert_eq!(task.description().contexts().collect::<Vec<_>>(), vec!["chapel"]);
assert_eq!(task.description().custom().collect::<Vec<_>>(), vec![("due", "2016-05-30")]);
use std::str::FromStr as _;

use tdtxt::{Task, Date, State, Priority, DateCompound};

let line = "x (A) 2016-05-20 2016-04-30 measure space for +chapelShelving @chapel due:2016-05-30";
let task = Task::build()
    .state(State::Done)
    .priority(Priority::A)
    .date_compound(DateCompound::completed(Date::from_ymd(2016, 4, 30), Date::from_ymd(2016, 5, 20)))
    .build("measure space for +chapelShelving @chapel due:2016-05-30");

assert_eq!(format!("{}", task), line);

assert_eq!(task.state(), &State::Done);
assert_eq!(task.priority(), Some(&Priority::A));
assert_eq!(task.date_compound(), Some(&DateCompound::Completed { created: Date::from_ymd(2016, 4, 30), completed: Date::from_ymd(2016, 5, 20) }));
assert_eq!(task.description().description(), "measure space for +chapelShelving @chapel due:2016-05-30");
assert_eq!(task.description().projects().collect::<Vec<_>>(), vec!["chapelShelving"]);
assert_eq!(task.description().contexts().collect::<Vec<_>>(), vec!["chapel"]);
assert_eq!(task.description().custom().collect::<Vec<_>>(), vec![("due", "2016-05-30")]);

Features

Serde (serde)

Serialize and deserialize the Task struct with serde.

Examples

use tdtxt::{Task, Date, State, Priority, DateCompound};

let task_should = Task::build()
    .state(State::Done)
    .priority(Priority::A)
    .date_compound(DateCompound::completed(
        Date::from_ymd(2016, 4, 30),
        Date::from_ymd(2016, 5, 20),
    ))
    .build("measure space for +chapelShelving @chapel due:2016-05-30");

let json = serde_json::to_string_pretty(&task_should).unwrap();

Modules

The prelude exports all components needed for regular use.

Structs

An iterator of all the Component’s of a Description.

A simple date structure, which represents the date in the format yyyy-mm-dd.

Represents the description part of a Task.

A generic error which can occur during parsing of a date compound.

A generic error which can occur during parsing of a date.

A generic error which can occur during parsing of a description.

A generic error which can occur during parsing of a priority.

A generic error which can occur during parsing of a state.

This struct represents errors which may occur during the parsing of a Task.

A very basic date type used when feature chrono is not active.

Represents the whole task.

A builder for a task.

Enums

A single component of a Description.

Represents the attached dates a Task can have.

Represents the priority a Task can have.

Represents the state of Task.