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
//! The module describes output

use std::collections::BTreeMap;
use error::{Error, ProtoError};
use std::convert::From;

use convert::FromMap;

/// Sound output
#[derive(Clone, Debug, PartialEq, RustcEncodable)]
pub struct Output {
    /// id
    pub id: u32,
    /// name
    pub name: String,
    /// enabled state
    pub enabled: bool,
}

impl FromMap for Output {
    fn from_map(map: BTreeMap<String, String>) -> Result<Output, Error> {
        Ok(Output {
            id: get_field!(map, "outputid"),
            name: try!(map.get("outputname")
                          .map(|v| v.to_owned())
                          .ok_or(Error::Proto(ProtoError::NoField("outputname")))),
            enabled: get_field!(map, bool "outputenabled"),
        })
    }
}