~exprez135/castor

ref: 193de0c2079abf371286916b814804f34dd97087 castor/src/protocols.rs -rw-r--r-- 1.1 KiB
193de0c2Julien Blanchard [gopher] Fix parsing of h type 2 years ago
                                                                                
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
59
60
61
62
63
64
65
66
use url::Url;

pub trait Protocol {
    fn get_source_str(&self) -> &str;
    fn get_source_url(&self) -> Url;
    fn get_scheme(&self) -> Scheme;
}

pub struct Gemini {
    pub source: String,
}
pub struct Gopher {
    pub source: String,
}
pub struct Finger {
    pub source: String,
}

impl Protocol for Finger {
    fn get_source_str(&self) -> &str {
        &self.source
    }

    fn get_source_url(&self) -> Url {
        Url::parse(&self.source).unwrap()
    }

    fn get_scheme(&self) -> Scheme {
        Scheme::Finger
    }
}

impl Protocol for Gemini {
    fn get_source_str(&self) -> &str {
        &self.source
    }

    fn get_source_url(&self) -> Url {
        Url::parse(&self.source).unwrap()
    }

    fn get_scheme(&self) -> Scheme {
        Scheme::Gemini
    }
}

impl Protocol for Gopher {
    fn get_source_str(&self) -> &str {
        &self.source
    }

    fn get_source_url(&self) -> Url {
        Url::parse(&self.source).unwrap()
    }

    fn get_scheme(&self) -> Scheme {
        Scheme::Gopher
    }
}

#[derive(PartialEq)]
pub enum Scheme {
    Finger,
    Gemini,
    Gopher,
}