1use crate::convert::FromIter;
4use crate::error::Error;
5
6#[derive(Clone, Debug, PartialEq)]
8pub struct Plugin {
9 pub name: String,
11 pub suffixes: Vec<String>,
13 pub mime_types: Vec<String>,
15}
16
17impl FromIter for Vec<Plugin> {
18 fn from_iter<I: Iterator<Item = Result<(String, String), Error>>>(iter: I) -> Result<Self, Error> {
19 let mut result = Vec::new();
20 let mut plugin: Option<Plugin> = None;
21 for reply in iter {
22 let (a, b) = reply?;
23 match &*a {
24 "plugin" => {
25 if let Some(p) = plugin {
26 result.push(p)
27 }
28
29 plugin = Some(Plugin { name: b, suffixes: Vec::new(), mime_types: Vec::new() });
30 }
31 "mime_type" => {
32 if let Some(p) = plugin.as_mut() {
33 p.mime_types.push(b)
34 }
35 }
36 "suffix" => {
37 if let Some(p) = plugin.as_mut() {
38 p.suffixes.push(b)
39 }
40 }
41 _ => unreachable!(),
42 }
43 }
44 if let Some(p) = plugin {
45 result.push(p)
46 }
47 Ok(result)
48 }
49}