#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
#[xml(tag = "InLine", strict(unknown_attribute, unknown_element))]
pub struct InLine<'a> {
#[xml(child = "AdSystem")]
pub ad_system: AdSystem<'a>,
#[xml(flatten_text = "Error", cdata, default)]
pub errors: Vec<std::borrow::Cow<'a, str>>,
#[xml(child = "Extensions", default)]
pub extensions: Option<crate::Extensions>,
#[xml(child = "Impression")]
pub impressions: Vec<Impression<'a>>,
#[xml(child = "Pricing", default)]
pub pricing: Option<Pricing<'a>>,
#[xml(child = "ViewableImpression", default)]
pub viewable_impression: Option<crate::ViewableImpression<'a>>,
#[xml(flatten_text = "AdServingId")]
pub ad_serving_id: std::borrow::Cow<'a, str>,
#[xml(flatten_text = "AdTitle")]
pub ad_title: std::borrow::Cow<'a, str>,
#[xml(child = "AdVerifications", default)]
pub ad_verifications: Option<crate::AdVerifications<'a>>,
#[xml(flatten_text = "Advertiser", default)]
pub advertiser: Option<std::borrow::Cow<'a, str>>,
#[xml(child = "Category", default)]
pub categories: Vec<Category<'a>>,
#[xml(child = "Creatives")]
pub creatives: crate::Creatives<'a>,
#[xml(flatten_text = "Description", default)]
pub description: Option<std::borrow::Cow<'a, str>>,
#[xml(flatten_text = "Expires", default)]
pub expires: Option<i32>,
#[xml(child = "Survey", default)]
pub surveys: Option<Survey<'a>>,
}
#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
#[xml(tag = "AdSystem", strict(unknown_attribute, unknown_element))]
pub struct AdSystem<'a> {
#[xml(attr = "version", default)]
pub version: Option<std::borrow::Cow<'a, str>>,
#[xml(text)]
pub name: std::borrow::Cow<'a, str>,
}
#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
#[xml(tag = "Impression", strict(unknown_attribute, unknown_element))]
pub struct Impression<'a> {
#[xml(attr = "id", default)]
pub id: Option<std::borrow::Cow<'a, str>>,
#[xml(text, cdata)]
pub uri: std::borrow::Cow<'a, str>,
}
#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
#[xml(tag = "Category", strict(unknown_attribute, unknown_element))]
pub struct Category<'a> {
#[xml(attr = "authority")]
pub authority: std::borrow::Cow<'a, str>,
#[xml(text)]
pub code: std::borrow::Cow<'a, str>,
}
#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
#[xml(tag = "Pricing", strict(unknown_attribute, unknown_element))]
pub struct Pricing<'a> {
#[xml(attr = "model")]
pub model: PriceModel,
#[xml(attr = "currency")]
pub currency: std::borrow::Cow<'a, str>,
#[xml(text)]
pub price: f64,
}
#[derive(Default, PartialEq, Clone, Copy, Debug)]
pub enum PriceModel {
#[default]
Cpm,
Cpc,
Cpe,
Cpv,
}
impl std::str::FromStr for PriceModel {
type Err = crate::VastParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"CPM" | "cpm" => Self::Cpm,
"CPC" | "cpc" => Self::Cpc,
"CPE" | "cpe" => Self::Cpe,
"CPV" | "cpv" => Self::Cpv,
_ => {
return Err(crate::VastParseError::new(format!(
"price model parsing error: '{s}'",
)));
}
})
}
}
impl std::fmt::Display for PriceModel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PriceModel::Cpm => write!(f, "cpm"),
PriceModel::Cpc => write!(f, "cpc"),
PriceModel::Cpe => write!(f, "cpe"),
PriceModel::Cpv => write!(f, "cpv"),
}
}
}
#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
#[xml(tag = "Survey", strict(unknown_attribute, unknown_element))]
pub struct Survey<'a> {
#[xml(attr = "type", default)]
pub mime_type: Option<std::borrow::Cow<'a, str>>,
#[xml(text, cdata)]
pub uri: std::borrow::Cow<'a, str>,
}