TodoList

Struct TodoList 

Source
pub struct TodoList {
    pub name: String,
    pub list: Vec<Todo>,
}
Expand description

Simple todo list structure.

Todos can be grouped together in so called todo lists (as in the real world). Therefore, the TodoList struct can be used. It’s a simple data structure that holds a number of Todo items and offers all basic functions for managing them.

Fields§

§name: String

Name of the todo list.

§list: Vec<Todo>

The actual vector of Todo items.

Implementations§

Source§

impl TodoList

Source

pub fn new(name: &str) -> TodoList

Create a new list with the given name.

§Example
let mut list = TodoList::new("important");
Source

pub fn add(&mut self, new_todo: Todo)

Add a new todo to the list.

§Example
list.add(Todo::new(0,"A first important todo", None));
Source

pub fn contains_id(&self, id: u32) -> TdoResult<usize>

Check if the list contains a todo with the given ID.

This function returns a TdoResult, wich will contion a TodoError::NotInList if the list does not contain any todo with the given ID or the position in the list.

Source

pub fn done_id(&mut self, id: u32) -> TdoResult<()>

Mark a todo from the list with the given ID as done.

This function returns a TdoResult, which will contain a TodoError::NotInList if the list does not contain any todo with the given ID.

Source

pub fn remove_id(&mut self, id: u32) -> TdoResult<Todo>

Remove a todo with the given ID from the list.

This function returns a TdoResult, which will contain the removed Todo itself or a TodoError::NotInList if the list does not contain any todo with the given id.

Source

pub fn list_undone(&self) -> Vec<Todo>

Search for all undone todos in the list.

Returns a vector of all undone todos.

Source

pub fn clean(&mut self)

Remove all done todos from the list.

Source

pub fn pop_id(&mut self, todo_id: u32) -> TdoResult<Todo>

Remove a todo with a specific ID from the list.

Source

pub fn insert_todo(&mut self, todo: Todo)

Insert an existing todo into the list, preserving the ordering of the internal list.

Trait Implementations§

Source§

impl Clone for TodoList

Source§

fn clone(&self) -> TodoList

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 TodoList

Source§

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

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

impl Default for TodoList

Instanciates a default TodoList. This function is invoked when a Tdo container structure is instanciated.

Source§

fn default() -> TodoList

Returns the “default value” for a type. Read more
Source§

impl Deserialize for TodoList

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 TodoList

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§

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.