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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
use std::borrow::Cow; pub struct Response<'a> { pub session_attributes: Option<BTreeMap<String, serde_json::value::Value>>, pub card: Option<Card<'a>>, pub reprompt: Option<OutputSpeech<'a>>, pub output_speech: Option<OutputSpeech<'a>>, pub should_end_session: bool, } pub enum OutputSpeech<'a> { Text(Cow<'a, str>), Ssml(Cow<'a, str>), } pub enum Card<'a> { Simple(SimpleCard<'a>), Standard(StandardCard<'a>), LinkAccount, } pub struct SimpleCard<'a> { pub title: Cow<'a, str>, pub content: Cow<'a, str>, } pub struct StandardCard<'a> { pub title: Cow<'a, str>, pub text: Cow<'a, str>, pub image: Image<'a>, } #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] const _IMPL_SERIALIZE_FOR_ResponseInternal: () = { extern crate serde as _serde; #[automatically_derived] impl <'a> _serde::ser::Serialize for ResponseInternal<'a> { fn serialize<__S>(&self, _serializer: &mut __S) -> ::std::result::Result<(), __S::Error> where __S: _serde::ser::Serializer { let mut __serde_state = try!(_serializer . serialize_struct ( "ResponseInternal" , 0 + 1 + 1 + 1 )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "version" , & self . version )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "sessionAttributes" , & self . sessionAttributes )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "response" , & self . response )); _serializer.serialize_struct_end(__serde_state) } } }; #[allow(non_snake_case)] struct ResponseInternal<'a> { version: &'static str, sessionAttributes: Option<BTreeMap<String, serde_json::value::Value>>, response: ResponseBody<'a>, } #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] const _IMPL_SERIALIZE_FOR_ResponseBody: () = { extern crate serde as _serde; #[automatically_derived] impl <'a> _serde::ser::Serialize for ResponseBody<'a> { fn serialize<__S>(&self, _serializer: &mut __S) -> ::std::result::Result<(), __S::Error> where __S: _serde::ser::Serializer { let mut __serde_state = try!(_serializer . serialize_struct ( "ResponseBody" , 0 + 1 + 1 + 1 + 1 )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "outputSpeech" , & self . outputSpeech )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "card" , & self . card )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "reprompt" , & self . reprompt )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "shouldEndSession" , & self . shouldEndSession )); _serializer.serialize_struct_end(__serde_state) } } }; #[allow(non_snake_case)] struct ResponseBody<'a> { outputSpeech: Option<OutputSpeechInternal<'a>>, card: Option<CardInternal<'a>>, reprompt: Option<OutputSpeechInternal<'a>>, shouldEndSession: bool, } #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] const _IMPL_SERIALIZE_FOR_OutputSpeechInternal: () = { extern crate serde as _serde; #[automatically_derived] impl <'a> _serde::ser::Serialize for OutputSpeechInternal<'a> { fn serialize<__S>(&self, _serializer: &mut __S) -> ::std::result::Result<(), __S::Error> where __S: _serde::ser::Serializer { let mut __serde_state = try!(_serializer . serialize_struct ( "OutputSpeechInternal" , 0 + 1 + 1 + 1 )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "type" , & self . speech_type )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "text" , & self . text )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "ssml" , & self . ssml )); _serializer.serialize_struct_end(__serde_state) } } }; struct OutputSpeechInternal<'a> { speech_type: SpeechType, text: Option<Cow<'a, str>>, ssml: Option<Cow<'a, str>>, } impl <'a> From<OutputSpeech<'a>> for OutputSpeechInternal<'a> { fn from(os: OutputSpeech<'a>) -> OutputSpeechInternal<'a> { match os { OutputSpeech::Text(t) => OutputSpeechInternal{speech_type: SpeechType::PlainText, text: Some(t), ssml: None,}, OutputSpeech::Ssml(s) => OutputSpeechInternal{speech_type: SpeechType::SSML, text: None, ssml: Some(s),}, } } } #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] const _IMPL_SERIALIZE_FOR_SpeechType: () = { extern crate serde as _serde; #[automatically_derived] impl _serde::ser::Serialize for SpeechType { fn serialize<__S>(&self, _serializer: &mut __S) -> ::std::result::Result<(), __S::Error> where __S: _serde::ser::Serializer { match *self { SpeechType::PlainText => _serde::ser::Serializer::serialize_unit_variant(_serializer, "SpeechType", 0usize, "PlainText"), SpeechType::SSML => _serde::ser::Serializer::serialize_unit_variant(_serializer, "SpeechType", 1usize, "SSML"), } } } }; #[allow(non_camel_case_types)] enum SpeechType { PlainText, SSML, } #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] const _IMPL_SERIALIZE_FOR_CardInternal: () = { extern crate serde as _serde; #[automatically_derived] impl <'a> _serde::ser::Serialize for CardInternal<'a> { fn serialize<__S>(&self, _serializer: &mut __S) -> ::std::result::Result<(), __S::Error> where __S: _serde::ser::Serializer { let mut __serde_state = try!(_serializer . serialize_struct ( "CardInternal" , 0 + 1 + 1 + 1 + 1 + 1 )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "type" , & self . card_type )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "title" , & self . title )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "content" , & self . content )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "text" , & self . text )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "image" , & self . image )); _serializer.serialize_struct_end(__serde_state) } } }; struct CardInternal<'a> { card_type: CardType, title: Option<Cow<'a, str>>, content: Option<Cow<'a, str>>, text: Option<Cow<'a, str>>, image: Option<Image<'a>>, } impl <'a> From<Card<'a>> for CardInternal<'a> { fn from(c: Card<'a>) -> CardInternal<'a> { match c { Card::Simple(sc) => CardInternal{card_type: CardType::Simple, title: Some(sc.title), content: Some(sc.content), text: None, image: None,}, Card::Standard(sc) => CardInternal{card_type: CardType::Standard, title: Some(sc.title), content: None, text: Some(sc.text), image: Some(sc.image),}, Card::LinkAccount => CardInternal{card_type: CardType::LinkAccount, title: None, content: None, text: None, image: None,}, } } } #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] const _IMPL_SERIALIZE_FOR_CardType: () = { extern crate serde as _serde; #[automatically_derived] impl _serde::ser::Serialize for CardType { fn serialize<__S>(&self, _serializer: &mut __S) -> ::std::result::Result<(), __S::Error> where __S: _serde::ser::Serializer { match *self { CardType::Simple => _serde::ser::Serializer::serialize_unit_variant(_serializer, "CardType", 0usize, "Simple"), CardType::Standard => _serde::ser::Serializer::serialize_unit_variant(_serializer, "CardType", 1usize, "Standard"), CardType::LinkAccount => _serde::ser::Serializer::serialize_unit_variant(_serializer, "CardType", 2usize, "LinkAccount"), } } } }; enum CardType { Simple, Standard, LinkAccount, } #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] const _IMPL_SERIALIZE_FOR_Image: () = { extern crate serde as _serde; #[automatically_derived] impl <'a> _serde::ser::Serialize for Image<'a> { fn serialize<__S>(&self, _serializer: &mut __S) -> ::std::result::Result<(), __S::Error> where __S: _serde::ser::Serializer { let mut __serde_state = try!(_serializer . serialize_struct ( "Image" , 0 + 1 + 1 )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "smallImageUrl" , & self . small_image_url )); try!(_serializer . serialize_struct_elt ( & mut __serde_state , "largeImageUrl" , & self . large_image_url )); _serializer.serialize_struct_end(__serde_state) } } }; pub struct Image<'a> { small_image_url: Option<Cow<'a, str>>, large_image_url: Option<Cow<'a, str>>, } impl <'a> From<Response<'a>> for ResponseInternal<'a> { fn from(r: Response<'a>) -> ResponseInternal<'a> { ResponseInternal{version: "1.0", sessionAttributes: r.session_attributes, response: ResponseBody{outputSpeech: r.output_speech.map(|os| os.into()), card: r.card.map(|c| c.into()), reprompt: r.reprompt.map(|r| r.into()), shouldEndSession: r.should_end_session,},} } }