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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
use std::error::Error as StdError; use std::fmt; use std::result; use event::*; #[derive(Debug, PartialEq)] pub struct Document { pub version: Version, pub head: Head, pub outlines: Vec<Outline>, } #[derive(Debug, PartialEq)] pub struct Version { pub major: u8, pub minor: u8, } #[derive(Debug, PartialEq)] pub struct Head { pub title: String, pub status: Option<u32>, } #[derive(Debug, PartialEq)] pub struct Group { pub text: String, pub key: String, pub outlines: Vec<Outline>, } #[derive(Debug, PartialEq)] pub struct Link { pub text: String, pub url: String, pub key: String, pub guide_id: String, } #[derive(Debug, PartialEq)] pub struct Audio { pub text: String, pub subtext: String, pub url: String, pub bitrate: u16, pub reliability: u16, pub format: Format, pub item: String, pub image: String, pub guide_id: String, pub genre_id: String, pub now_playing_id: String, pub preset_id: String, } #[derive(Debug, PartialEq)] pub enum Outline { Group(Group), Link(Link), Audio(Audio), } #[derive(Debug, PartialEq)] pub enum Format { Unknown, MP3, } impl Document { pub fn new() -> Document { Document { version: Version::new(), head: Head::new(), outlines: Vec::new(), } } } impl Version { pub fn new() -> Version { Version { major: 0, minor: 0, } } } impl Head { pub fn new() -> Head { Head { title: String::new(), status: None, } } } impl Group { pub fn new() -> Group { Group { text: String::new(), key: String::new(), outlines: vec![], } } } impl Link { pub fn new() -> Link { Link { text: String::new(), url: String::new(), key: String::new(), guide_id: String::new(), } } } impl Audio { pub fn new() -> Audio { Audio { text: String::new(), subtext: String::new(), url: String::new(), bitrate: 0, reliability: 0, format: Format::Unknown, item: String::new(), image: String::new(), guide_id: String::new(), genre_id: String::new(), now_playing_id: String::new(), preset_id: String::new(), } } } impl From<OutlineEvent> for Outline { fn from(outline: OutlineEvent) -> Outline { match outline { OutlineEvent::Group { text, key } => { Outline::Group(Group { text: text, key: key, outlines: vec![], }) } OutlineEvent::Link(link) => Outline::Link(link), OutlineEvent::Audio(audio) => Outline::Audio(audio), } } } #[derive(Debug)] pub struct Error { pub description: String, } impl Error { pub fn new(description: &str) -> Error { Error { description: description.into() } } } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str(self.description()) } } impl StdError for Error { fn description(&self) -> &str { self.description.as_str() } fn cause(&self) -> Option<&StdError> { None } } pub type Result<T> = result::Result<T, Error>;