1use std::iter;
2
3#[derive(Clone)]
4pub struct AnimeCollection(Vec<Anime>);
5
6impl AnimeCollection {
7 fn new() -> AnimeCollection {
8 AnimeCollection(Vec::new())
9 }
10
11 fn add(&mut self, elem: Anime) {
12 self.0.push(elem);
13 }
14
15 pub fn get_elem(&self, index: usize) -> Anime {
16 self.0[index].clone()
17 }
18
19 pub fn print_ele(&self) {
20 let mut i = 1;
21
22 for anime in self.0.iter() {
23 println!("{}. {}", i, anime.title);
24 i += 1;
25 }
26 }
27}
28
29impl iter::Iterator for AnimeCollection {
30 type Item = Anime;
31 fn next(&mut self) -> Option<Self::Item> {
32 self.0.pop()
33 }
34}
35
36impl iter::FromIterator<Anime> for AnimeCollection {
37 fn from_iter<I: IntoIterator<Item = Anime>>(iter: I) -> Self {
38 let mut c = AnimeCollection::new();
39
40 for i in iter {
41 c.add(i);
42 }
43
44 c
45 }
46}
47
48#[derive(Clone, Debug, Default)]
49pub struct Anime {
50 pub title: String,
51 pub url: String,
52 pub episodes: Vec<u32>,
53}