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
//! The module defines playlist data structures

use time::{Tm, strptime};

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

/// Playlist
#[derive(Clone, Debug, PartialEq)]
pub struct Playlist {
    /// name
    pub name: String,
    /// last modified
    pub last_mod: Tm,
}

impl FromMap for Playlist {
    fn from_map(map: BTreeMap<String, String>) -> Result<Playlist, Error> {
        Ok(Playlist {
            name: try!(map.get("playlist")
                          .map(|v| v.to_owned())
                          .ok_or(Error::Proto(ProtoError::NoField("playlist")))),
            last_mod: try!(map.get("Last-Modified")
                              .ok_or(Error::Proto(ProtoError::NoField("Last-Modified")))
                              .and_then(|v| strptime(&*v, "%Y-%m-%dT%H:%M:%S%Z").map_err(From::from))),
        })
    }
}