1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use serde_derive::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Meta {
pub title: String,
pub description: String,
pub thumbnail: String
}
#[derive(Clone, Debug, PartialEq)]
pub enum MetaType{
Og,
Tw,
Twitter,
Facebook,
Instagram,
Manual
}
#[derive(Debug, Clone)]
pub struct MetaIterator {
meta: MetaType,
next: u32
}
impl Iterator for MetaIterator {
type Item = MetaType;
fn next(&mut self) -> Option<Self::Item> {
self.next += 1;
match self.next {
1 => Some(MetaType::Og),
2 => Some(MetaType::Tw),
3 => Some(MetaType::Manual),
_ => None
}
}
}
impl IntoIterator for MetaType {
type IntoIter = MetaIterator;
type Item = MetaType;
fn into_iter(self) -> Self::IntoIter {
MetaIterator{ meta: self , next: 0 }
}
}
impl Meta {
pub fn new(title: &str, description: &str, thumbnail: &str ) -> Self {
Meta {title: title.to_string() , description: description.to_string(), thumbnail: thumbnail.to_string()}
}
}