vast4_rs/
vast.rs

1/// IAB VAST (Video Ad Serving Template).
2///
3/// ```text
4/// <xs:element name="VAST" >
5///   <xs:complexType>
6///     <xs:attribute name="version" type="xs:string" use="required">
7///     <xs:choice>
8///       <xs:element name="Ad" minOccurs="0" maxOccurs="unbounded" >
9///       <xs:element name="Error" minOccurs="0" maxOccurs="unbounded" type="xs:anyURI" >
10///     </xs:choice>
11///   </xs:complexType>
12/// </xs:element>
13/// ```
14#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
15#[xml(tag = "VAST")]
16pub struct Vast<'a> {
17    /// A float (number with decimal) to indicate the VAST version being used.
18    #[xml(attr = "version", default)]
19    pub version: std::borrow::Cow<'a, str>,
20
21    /// Top-level element, wraps each ad in the response or ad unit in an ad pod. This MUST be
22    /// present unless an `Error` element is present.
23    #[xml(child = "Ad", default)]
24    pub ads: Vec<crate::Ad<'a>>,
25    /// Used when there is no ad response. When the ad server does not or cannot return an
26    /// [Ad](crate::Ad). If included the video player must send a request to the URI provided
27    /// (Sec 3.2.1).
28    #[xml(flatten_text = "Error", cdata, default)]
29    pub errors: Vec<std::borrow::Cow<'a, str>>,
30}
31
32crate::declare_test!(
33    test_vast_errors,
34    Vast,
35    r#"<VAST version="4.2"><Error><![CDATA[hoge]]></Error><Error><![CDATA[fuga]]></Error></VAST>"#,
36    Vast {
37        version: "4.2".into(),
38        errors: vec!["hoge".into(), "fuga".into()],
39        ..Default::default()
40    }
41);