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§
- prelude
- The prelude exports all components needed for regular use.
Structs§
- Components
- An iterator of all the
Component
’s of aDescription
. - Date
- A simple date structure, which represents the date in the format
yyyy-mm-dd
. - Description
- Represents the description part of a
Task
. - Parse
Date Compound Error - A generic error which can occur during parsing of a date compound.
- Parse
Date Error - A generic error which can occur during parsing of a date.
- Parse
Description Error - A generic error which can occur during parsing of a description.
- Parse
Priority Error - A generic error which can occur during parsing of a priority.
- Parse
State Error - A generic error which can occur during parsing of a state.
- Parse
Task Error - This struct represents errors which may occur during the parsing of a
Task
. - Simple
Date - A very basic date type used when feature
chrono
is not active. - Task
- Represents the whole task.
- Task
Builder - A builder for a task.
Enums§
- Component
- A single component of a
Description
. - Date
Compound - Represents the attached dates a
Task
can have. - Priority
- Represents the priority a
Task
can have. - State
- Represents the state of
Task
.