tdtxt

Build Crates.io Documentation GitHub Issues Unlicense License

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

STATE

This crate is still in development, the api may not stable and could change in the future.

This crate should not be used in production code.

Usage

Add it to the dependencies of your Cargo.toml:

toml [dependencies] tdtxt = "0.2"

Then use it:

```rust 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();

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

```rust 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::ymd(2016, 4, 30), Date::ymd(2016, 5, 20))) .build("measure space for +chapelShelving @chapel due:2016-05-30");

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

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

Examples

For more detailed examples, see the examples/ directory.

Run one:

```bash

Example filter_open

cargo run --example filter_open -- examples/todos.txt ```

Features

Serde (serde)

Serialize and deserialize the Task struct with serde.

Examples

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

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

let json = serdejson::tostringpretty(&taskshould).unwrap(); println!("{}", &json); ```

Example json output:

json { "state": "Done", "priority": "A", "created": "2016-04-30", "completed": "2016-05-20", "description": "measure space for +chapelShelving @chapel due:2016-05-30" }

NOTE

The order in which created and completed appear matters.