grab_meta/
meta.rs

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