disco_quick/
shared.rs

1use crate::{
2    parser::ParserError,
3    util::{find_attr, find_attr_optional},
4};
5use quick_xml::events::BytesStart;
6
7#[derive(Clone, Debug, Default, PartialEq, Eq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct Image {
10    pub r#type: String,
11    pub uri: Option<String>,
12    pub uri150: Option<String>,
13    pub width: i16,
14    pub height: i16,
15}
16
17impl Image {
18    pub fn from_event(ev: &BytesStart) -> Result<Self, ParserError> {
19        Ok(Image {
20            r#type: find_attr(ev, b"type")?.to_string(),
21            uri: find_attr_optional(ev, b"uri")?.map(|u| u.to_string()),
22            uri150: find_attr_optional(ev, b"uri150")?.map(|u| u.to_string()),
23            width: find_attr(ev, b"width")?.parse()?,
24            height: find_attr(ev, b"height")?.parse()?,
25        })
26    }
27}