pub struct Tdo {
pub lists: Vec<TodoList>,
/* private fields */
}Expand description
Basic container structure for a set of todo lists.
This data structure acts as a conatiner for all todo lists and its associated todos.
The whole tdo microcosm settles around this structure
which is also used for (de-)serialization.
When instanciated, it comes with an empty default list.
Fields§
§lists: Vec<TodoList>A vector of all todo lists.
Implementations§
Source§impl Tdo
impl Tdo
Sourcepub fn new() -> Tdo
pub fn new() -> Tdo
Create a new Tdo container.
Each new container is instanciated with a default TodoList.
§Example
let tdo = Tdo::new();Sourcepub fn load(path: &str) -> TdoResult<Tdo>
pub fn load(path: &str) -> TdoResult<Tdo>
Load a saved Tdo container from a JSON file.
This function returns a ResultType which will yield the
deserialized JSON or a serde_json::Error.
§Example
let mut tdo = Tdo::load("foo.json");Sourcepub fn save(&self, path: &str) -> TdoResult<()>
pub fn save(&self, path: &str) -> TdoResult<()>
Dump the Tdo container to a JSON file.
This function returns a ResultType yielding a StorageError::SaveFailure
if the JSON file could not be opened/saved.
§Example
let res = tdo.save("foo.json");
assert_eq!(res.unwrap(), ());Sourcepub fn set_gh_token(&mut self, token: Option<&str>)
pub fn set_gh_token(&mut self, token: Option<&str>)
Sets the GitHub access token.
Sourcepub fn get_gh_token(&self) -> Option<String>
pub fn get_gh_token(&self) -> Option<String>
Returns an Option
Sourcepub fn remove_list(&mut self, list_name: &str) -> TdoResult<()>
pub fn remove_list(&mut self, list_name: &str) -> TdoResult<()>
Removes a list from the container.
Sourcepub fn add_todo(&mut self, list_name: Option<&str>, todo: Todo) -> TdoResult<()>
pub fn add_todo(&mut self, list_name: Option<&str>, todo: Todo) -> TdoResult<()>
Add a todo to the todo list, identified by its name.
This function returns a ResultType with a TodoError::NoSuchList
if there is no matching list found.
Sourcepub fn find_id(&self, id: u32) -> TdoResult<usize>
pub fn find_id(&self, id: u32) -> TdoResult<usize>
Cycle through all todo lists and find the list which contains the todo with the given ID
This function retuns a ResultType with a TodoError::NotInList
if there is no list found or a usize with the postition of the list in lists.
Sourcepub fn done_id(&mut self, id: u32) -> TdoResult<()>
pub fn done_id(&mut self, id: u32) -> TdoResult<()>
Cycle through all todo lists and mark a todo with the given ID as done. This function has no return value and thus won’t indicate whether there was a matching todo found.
Sourcepub fn remove_id(&mut self, id: u32) -> TdoResult<()>
pub fn remove_id(&mut self, id: u32) -> TdoResult<()>
Cycle through all todo lists and remove a todo with the given id. This function has no return value and thus won’t indicate whether there was a matching todo found.
Sourcepub fn clean_lists(&mut self)
pub fn clean_lists(&mut self)
Remove all todos that have been marked as done from all todo lists.
Sourcepub fn clean_list(&mut self, list: &str) -> TdoResult<()>
pub fn clean_list(&mut self, list: &str) -> TdoResult<()>
Remove all todos that have been marked as done from a given todo list.
Sourcepub fn get_highest_id(&self) -> u32
pub fn get_highest_id(&self) -> u32
Get the highest ID used in the tdo container.