Tdo

Struct Tdo 

Source
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

Source

pub fn new() -> Tdo

Create a new Tdo container. Each new container is instanciated with a default TodoList.

§Example
let tdo = Tdo::new();
Source

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");
Source

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(), ());
Source

pub fn set_gh_token(&mut self, token: Option<&str>)

Sets the GitHub access token.

Source

pub fn get_gh_token(&self) -> Option<String>

Returns an Option of the private access_token field.

Source

pub fn add_list(&mut self, list: TodoList) -> TdoResult<()>

Add a todo list to the container.

Source

pub fn remove_list(&mut self, list_name: &str) -> TdoResult<()>

Removes a list from the container.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clean_lists(&mut self)

Remove all todos that have been marked as done from all todo lists.

Source

pub fn clean_list(&mut self, list: &str) -> TdoResult<()>

Remove all todos that have been marked as done from a given todo list.

Source

pub fn get_highest_id(&self) -> u32

Get the highest ID used in the tdo container.

Source

pub fn move_todo(&mut self, id: u32, target_list: &str) -> TdoResult<()>

Move a todo between two lists.

Trait Implementations§

Source§

impl Clone for Tdo

Source§

fn clone(&self) -> Tdo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tdo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deserialize for Tdo

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Tdo

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Tdo

§

impl RefUnwindSafe for Tdo

§

impl Send for Tdo

§

impl Sync for Tdo

§

impl Unpin for Tdo

§

impl UnwindSafe for Tdo

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToJson for T
where T: Serialize + ?Sized,

Source§

fn to_json(&self) -> Result<Value, Error>

Represent self as a serde_json::Value. Note that Value is not a JSON string. If you need a string, use serde_json::to_string instead. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.