File size: 1,493 Bytes
3374e90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
bitflags::bitflags! {
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
    pub struct Capabilities: u32 {
        const HOME      = 1 << 0;
        const CATEGORY  = 1 << 1;
        const SEARCH    = 1 << 2;
        const INFO      = 1 << 3;
        const SERVERS   = 1 << 4;
        const STREAM    = 1 << 5;
        const SUBTITLES = 1 << 6;
        const ARTICLES  = 1 << 7;
    }
}

impl Capabilities {
    pub fn for_method(name: &str) -> Self {
        match name {
            "get_home" => Self::HOME,
            "get_category" => Self::CATEGORY,
            "search" => Self::SEARCH,
            "get_info" => Self::INFO,
            "get_servers" => Self::SERVERS,
            "resolve_stream" => Self::STREAM,
            "search_subtitles" | "download_subtitle" => Self::SUBTITLES,
            "get_articles" | "search_articles" => Self::ARTICLES,
            _ => Self::empty(),
        }
    }

    pub fn from_manifest(p: &crate::manifest::ProvidesSpec) -> Self {
        let mut c = Self::empty();
        if p.home { c |= Self::HOME; }
        if p.category { c |= Self::CATEGORY; }
        if p.search { c |= Self::SEARCH; }
        if p.info { c |= Self::INFO; }
        if p.servers { c |= Self::SERVERS; }
        if p.stream { c |= Self::STREAM; }
        if p.subtitles { c |= Self::SUBTITLES; }
        if p.articles { c |= Self::ARTICLES; }
        c
    }

    pub fn has(self, cap: Self) -> bool { self.contains(cap) }
}