Trait mal::list::List
[−]
[src]
pub trait List { type Entry: ListEntry; fn list_type() -> ListType; fn mal(&self) -> &MAL; fn read_entries(&self) -> Result<Vec<Self::Entry>, Error> { ... } fn add(&self, entry: &mut Self::Entry) -> Result<(), Error> { ... } fn update(&self, entry: &mut Self::Entry) -> Result<(), Error> { ... } fn delete(&self, entry: &Self::Entry) -> Result<(), Error> { ... } fn delete_id(&self, id: u32) -> Result<(), Error> { ... } }
Contains methods that perform common operations on a user's anime / manga list.
Associated Types
Required Methods
fn list_type() -> ListType
Returns what type of list this is.
fn mal(&self) -> &MAL
Returns a reference to the MAL client used to send requests to the API.
Provided Methods
fn read_entries(&self) -> Result<Vec<Self::Entry>, Error>
Requests and parses all entries on a user's anime / manga list.
Examples
use mal::MAL; use mal::list::List; // Create a new MAL instance let mal = MAL::new("username", "password"); // Read all list entries from the user's list let entries = mal.anime_list().read_entries().unwrap();
fn add(&self, entry: &mut Self::Entry) -> Result<(), Error>
Adds an entry to the user's anime / manga list.
If the entry is already on the user's list, nothing will happen.
Examples
use mal::{MAL, AnimeInfo}; use mal::list::List; use mal::list::anime::{AnimeEntry, WatchStatus}; // Create a new MAL instance let mal = MAL::new("username", "password"); // Search for "Toradora" on MyAnimeList let mut search_results = mal.search_anime("Toradora").unwrap(); // Use the first result's info let toradora_info = search_results.swap_remove(0); // Create a new anime list entry with Toradora's info let mut entry = AnimeEntry::new(toradora_info); // Set the entry's watched episodes to 5 and status to watching entry.set_watched_episodes(5).set_status(WatchStatus::Watching); // Add the entry to the user's anime list mal.anime_list().add(&mut entry).unwrap();
fn update(&self, entry: &mut Self::Entry) -> Result<(), Error>
Updates an entry on the user's anime / manga list.
If the entry is already on the user's list, nothing will happen.
Examples
use mal::{MAL, AnimeInfo}; use mal::list::List; use mal::list::anime::{AnimeEntry, WatchStatus}; // Create a new MAL instance let mal = MAL::new("username", "password"); // Get a handle to the user's anime list let anime_list = mal.anime_list(); // Get and parse all of the list entries let entries = anime_list.read_entries().unwrap(); // Find Toradora in the list entries let mut toradora_entry = entries.into_iter().find(|e| e.series_info.id == 4224).unwrap(); // Set new values for the list entry // In this case, the episode count will be updated to 25, the score will be set to 10, and the status will be set to completed toradora_entry.set_watched_episodes(25) .set_score(10) .set_status(WatchStatus::Completed); // Update the anime on the user's list anime_list.update(&mut toradora_entry).unwrap();
fn delete(&self, entry: &Self::Entry) -> Result<(), Error>
Removes an entry from the user's anime / manga list.
If the entry isn't already on the user's list, nothing will happen.
Examples
use mal::{MAL, AnimeInfo}; use mal::list::List; use mal::list::anime::{AnimeEntry, WatchStatus}; // Create a new MAL instance let mal = MAL::new("username", "password"); // Search for "Toradora" on MyAnimeList let mut search_results = mal.search_anime("Toradora").unwrap(); // Use the first result's info let toradora_info = search_results.swap_remove(0); // Get a handle to the user's anime list let anime_list = mal.anime_list(); // Get and parse all of the list entries let entries = anime_list.read_entries().unwrap(); // Find Toradora in the list entries let toradora_entry = entries.into_iter().find(|e| e.series_info.id == 4224).unwrap(); // Delete Toradora from the user's anime list anime_list.delete(&toradora_entry).unwrap();
fn delete_id(&self, id: u32) -> Result<(), Error>
Removes an entry from the user's anime / manga list by its id.
If the entry isn't already on the user's list, nothing will happen.
Examples
use mal::{MAL, AnimeInfo}; use mal::list::List; use mal::list::anime::{AnimeEntry, WatchStatus}; // Create a new MAL instance let mal = MAL::new("username", "password"); // Delete the anime with the id of 4224 (Toradora) from the user's anime list mal.anime_list().delete_id(4224).unwrap();
Implementors
impl<'a> List for AnimeList<'a> type Entry = AnimeEntry;
impl<'a> List for MangaList<'a> type Entry = MangaEntry;