Crates.io | tdtxt |
lib.rs | tdtxt |
version | 0.3.0 |
source | src |
created_at | 2021-08-26 14:16:19.968918 |
updated_at | 2021-09-07 14:53:17.446079 |
description | A serializer/deserializer for the todo.txt format |
homepage | https://github.com/Shemnei/tdtxt |
repository | https://github.com/Shemnei/tdtxt |
max_upload_size | |
id | 442594 |
size | 103,044 |
A rust library for de(serializing) files and text in the todo.txt format.
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.
Add it to the dependencies of your Cargo.toml
:
[dependencies]
tdtxt = "0.2"
Then use it:
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::ymd(2016, 4, 30), completed: Date::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::ymd(2016, 4, 30), Date::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::ymd(2016, 4, 30), completed: Date::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")]);
For more detailed examples, see the examples/
directory.
Run one:
# Example `filter_open`
cargo run --example filter_open -- examples/todos.txt
serde
)Serialize and deserialize the Task struct with serde.
use tdtxt::{Task, Date, State, Priority, DateCompound};
let task_should = 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");
let json = serde_json::to_string_pretty(&task_should).unwrap();
println!("{}", &json);
Example json output:
{
"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.