mpd 0.0.6

A client library for MPD (music player daemon), like libmpdclient but in Rust
//! This module defines MPD version type and parsing code

use std::str::FromStr;

use error::ParseError;

// Version {{{
/// MPD version
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, RustcEncodable)]
pub struct Version(pub u16, pub u16, pub u16);

impl FromStr for Version {
    type Err = ParseError;
    fn from_str(s: &str) -> Result<Version, ParseError> {
        let mut splits = s.splitn(3, '.').map(FromStr::from_str);
        match (splits.next(), splits.next(), splits.next()) {
            (Some(Ok(a)), Some(Ok(b)), Some(Ok(c))) => Ok(Version(a, b, c)),
            (Some(Err(e)), _, _) | (_, Some(Err(e)), _) | (_, _, Some(Err(e))) => Err(ParseError::BadInteger(e)),
            _ => Err(ParseError::BadVersion)
        }
    }
}
// }}}