pluginengine01 / crates /bex-types /src /capability.rs
krystv's picture
Upload 107 files
3374e90 verified
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) }
}