diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2022-08-07 20:47:54 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2022-08-07 20:47:54 -0400 |
| commit | ea77a8cf9c012fcd877d842fec85b0b5a442952c (patch) | |
| tree | 7f209c030b97a957497f152d161a9d7035311132 /vendored/mpd/src/plugin.rs | |
| parent | 0de7e9ac43f88aae3750ecfe25b5454fdd1ad015 (diff) | |
Diffstat (limited to 'vendored/mpd/src/plugin.rs')
| -rw-r--r-- | vendored/mpd/src/plugin.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/vendored/mpd/src/plugin.rs b/vendored/mpd/src/plugin.rs new file mode 100644 index 0000000..c490d02 --- /dev/null +++ b/vendored/mpd/src/plugin.rs @@ -0,0 +1,45 @@ +//! The module defines decoder plugin data structures + +use crate::convert::FromIter; +use crate::error::Error; + +/// Decoder plugin +#[derive(Clone, Debug, PartialEq, RustcEncodable)] +pub struct Plugin { + /// name + pub name: String, + /// supported file suffixes (extensions) + pub suffixes: Vec<String>, + /// supported MIME-types + pub mime_types: Vec<String>, +} + +impl FromIter for Vec<Plugin> { + fn from_iter<I: Iterator<Item = Result<(String, String), Error>>>(iter: I) -> Result<Self, Error> { + let mut result = Vec::new(); + let mut plugin: Option<Plugin> = None; + for reply in iter { + let (a, b) = reply?; + match &*a { + "plugin" => { + plugin.map(|p| result.push(p)); + + plugin = Some(Plugin { + name: b, + suffixes: Vec::new(), + mime_types: Vec::new(), + }); + } + "mime_type" => { + plugin.as_mut().map(|p| p.mime_types.push(b)); + } + "suffix" => { + plugin.as_mut().map(|p| p.suffixes.push(b)); + } + _ => unreachable!(), + } + } + plugin.map(|p| result.push(p)); + Ok(result) + } +} |