vast4_rs/
icon.rs

1/// The container for zero or one [`<Icon>`](Icon) element.
2///
3/// ```text
4/// <xs:element name="Icons">
5///   <xs:complexType>
6///     <xs:sequence>
7///       <xs:element name="Icon" minOccurs="1" maxOccurs="unbounded" type="vast:Icon_type">
8///     </xs:sequence>
9///   </xs:complexType>
10/// </xs:element>
11/// ```
12#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
13#[xml(tag = "Icons")]
14pub struct Icons<'a> {
15    /// The container for one or more [`<Icon>`](Icon) elements.
16    #[xml(child = "Icon", default)]
17    pub icons: Vec<Icon<'a>>,
18}
19
20/// The Icon is used to provide one or more creative files for the icon that represents
21/// the program being implemented along with any icon tracking elements.
22///
23/// ```text
24/// <xs:complexType name="Icon">
25///   <!-- CreativeResource_type -->
26///   <xs:sequence>
27///     <xs:element name="HTMLResource" minOccurs="0" maxOccurs="unbounded" type="vast:HTMLResource_type">
28///     <xs:element name="IFrameResource" minOccurs="0" maxOccurs="unbounded" type="xs:anyURI">
29///     <xs:element name="StaticResource" minOccurs="0" maxOccurs="unbounded">
30///   </xs:sequence>
31///
32///   <xs:attribute name="program" type="xs:string">
33///   <xs:attribute name="width" type="xs:integer">
34///   <xs:attribute name="height" type="xs:integer">
35///   <xs:attribute name="xPosition">
36///   <xs:attribute name="yPosition">
37///   <xs:attribute name="duration" type="xs:time">
38///   <xs:attribute name="offset" type="xs:time">
39///   <xs:attribute name="apiFramework" type="xs:string">
40///   <xs:attribute name="pxratio" type="xs:decimal">
41///   <xs:sequence>
42///     <xs:element name="IconClicks" minOccurs="0" maxOccurs="1">
43///     <xs:element name="IconViewTracking" minOccurs="0" maxOccurs="unbounded" type="xs:anyURI">
44///   </xs:sequence>
45/// </xs:complexType>
46/// ```
47#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
48#[xml(tag = "Icon")]
49pub struct Icon<'a> {
50    /// The program represented in the icon (e.g. "AdChoices").
51    #[xml(attr = "program", default)]
52    pub program: Option<std::borrow::Cow<'a, str>>,
53    /// Pixel width of the icon asset.
54    #[xml(attr = "width", default)]
55    pub width: Option<i32>,
56    /// Pixel height of the icon asset.
57    #[xml(attr = "height", default)]
58    pub height: Option<i32>,
59    /// The x-coordinate of the top, left corner of the icon asset relative to the ad display
60    /// area. Values of "left" or "right" also accepted and indicate the leftmost or rightmost
61    /// available position for the icon asset.
62    #[xml(attr = "xPosition", default)]
63    pub x_position: Option<XPosition>,
64    /// The y-coordinate of the top left corner of the icon asset relative to the ad display
65    /// area; values of "top" or "bottom" also accepted and indicate the topmost or
66    /// bottommost available position for the icon asset.
67    #[xml(attr = "yPosition", default)]
68    pub y_position: Option<YPosition>,
69    /// The duration the icon should be displayed unless clicked or ad is finished playing.
70    #[xml(attr = "duration", default)]
71    pub duration: Option<crate::Duration>,
72    /// The time of delay from when the associated linear creative begins playing to when
73    /// the icon should be displayed.
74    #[xml(attr = "offset", default = "00:00:00")]
75    pub offset: Option<crate::Offset>,
76    /// Identifies the API needed to execute the icon resource file if applicable.
77    #[xml(attr = "apiFramework", default)]
78    pub api_framework: Option<std::borrow::Cow<'a, str>>,
79    /// The pixel ratio for which the icon creative is intended. The pixel ratio is the ratio of
80    /// physical pixels on the device to the device-independent pixels. An ad intended for
81    /// display on a device with a pixel ratio that is twice that of a standard 1:1 pixel ratio
82    /// would use the value "2 " Default value is "1".
83    #[xml(attr = "pxratio", default)]
84    pub pxratio: Option<f32>,
85
86    /// The container for zero or more `<HTMLResource>` elements.
87    #[xml(flatten_text = "HTMLResource", cdata, default)]
88    pub html_resources: Vec<std::borrow::Cow<'a, str>>,
89    /// The container for zero or more `<IFrameResource>` elements.
90    #[xml(flatten_text = "IFrameResource", cdata, default)]
91    pub iframe_resources: Vec<std::borrow::Cow<'a, str>>,
92    /// The container for zero or more [`<StaticResource>`](crate::StaticResource) elements.
93    #[xml(child = "StaticResource", default)]
94    pub static_resources: Vec<crate::StaticResource<'a>>,
95
96    /// The container for zero or one [`<IconClicks>`](IconClicks) element.
97    #[xml(child = "IconClicks", default)]
98    pub icon_clicks: Option<IconClicks<'a>>,
99    /// The container for zero or more `<IconViewTracking>` elements.
100    #[xml(flatten_text = "IconViewTracking", cdata, default)]
101    pub icon_view_trackings: Vec<std::borrow::Cow<'a, str>>,
102}
103
104/// The x-cooridinate of the top, left corner of the icon asset relative to the ad display area.
105#[derive(PartialEq, Clone, Copy, Debug)]
106pub enum XPosition {
107    Coordinate(i32),
108    Left,
109    Right,
110}
111
112impl std::str::FromStr for XPosition {
113    type Err = crate::VastParseError;
114
115    fn from_str(s: &str) -> Result<Self, Self::Err> {
116        Ok(match s {
117            "left" | "Left" | "LEFT" => Self::Left,
118            "right" | "Right" | "RIGHT" => Self::Right,
119            _ => match s.parse::<i32>() {
120                Ok(x) => Self::Coordinate(x),
121                Err(_) => Self::Right,
122            },
123        })
124    }
125}
126
127impl std::fmt::Display for XPosition {
128    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
129        match self {
130            XPosition::Coordinate(x) => write!(f, "{x}"),
131            XPosition::Left => write!(f, "left"),
132            XPosition::Right => write!(f, "right"),
133        }
134    }
135}
136
137/// The y-cooridinate of the top left corner of the icon asset relative to the ad display area.
138#[derive(PartialEq, Clone, Copy, Debug)]
139pub enum YPosition {
140    Coordinate(i32),
141    Top,
142    Bottom,
143}
144
145impl std::str::FromStr for YPosition {
146    type Err = crate::VastParseError;
147
148    fn from_str(s: &str) -> Result<Self, Self::Err> {
149        Ok(match s {
150            "top" | "Top" | "TOP" => Self::Top,
151            "bottom" | "Bottom" | "BOTTOM" => Self::Bottom,
152            _ => match s.parse::<i32>() {
153                Ok(y) => Self::Coordinate(y),
154                Err(_) => Self::Bottom,
155            },
156        })
157    }
158}
159
160impl std::fmt::Display for YPosition {
161    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
162        match self {
163            YPosition::Coordinate(y) => write!(f, "{y}"),
164            YPosition::Top => write!(f, "top"),
165            YPosition::Bottom => write!(f, "bottom"),
166        }
167    }
168}
169
170/// The `<IconClicks>` element is a container for `<IconClickThrough>` and
171/// [`<ClickTracking>`](crate::ClickTracking).
172///
173/// ```text
174/// <xs:element name="IconClicks">
175///   <xs:complexType>
176///     <xs:sequence>
177///       <xs:element name="IconClickFallbackImages" minOccurs="0" maxOccurs="1">
178///       <xs:element name="IconClickThrough" minOccurs="0" maxOccurs="1" type="xs:anyURI">
179///       <xs:element name="IconClickTracking" minOccurs="0" maxOccurs="unbounded" type="vast:IconClickTracking_type">
180///     </xs:sequence>
181///   </xs:complexType>
182/// </xs:element>
183/// ```
184#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
185#[xml(tag = "IconClicks")]
186pub struct IconClicks<'a> {
187    /// The container for zero or one [`<IconClickFallbackImages>`](IconClickFallbackImages)
188    /// element.
189    #[xml(child = "IconClickFallbackImages", default)]
190    pub icon_click_fallback_images: Option<IconClickFallbackImages<'a>>,
191    /// The container for zero or one `<IconClickThrough>` element.
192    #[xml(flatten_text = "IconClickThrough", cdata, default)]
193    pub icon_click_through: Option<std::borrow::Cow<'a, str>>,
194    /// The container for zero or one [`<IconClickTracking>`](IconClickTracking) element.
195    #[xml(child = "IconClickTracking", default)]
196    pub icon_click_trackings: Vec<IconClickTracking<'a>>,
197}
198
199/// `<IconClickTracking>` is used to track click activity within the icon.
200///
201/// ```text
202/// <xs:complexType name="IconClickTracking_type">
203///   <xs:simpleContent>
204///     <xs:extension base="xs:anyURI">
205///       <xs:attribute name="id" type="xs:string" />
206///     </xs:extension>
207///   </xs:simpleContent>
208/// </xs:complexType>
209/// ```
210#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
211#[xml(tag = "IconClickTracking")]
212pub struct IconClickTracking<'a> {
213    /// An id for the click to be measured.
214    #[xml(attr = "id", default)]
215    pub id: Option<std::borrow::Cow<'a, str>>,
216
217    /// A URI to the tracking resource file to be called when a click corresponding to the
218    /// id attribute (if provided) occurs.
219    #[xml(text, cdata)]
220    pub uri: std::borrow::Cow<'a, str>,
221}
222
223/// The `<IconClickFallbackImages>` element is used to provide information disclosure for
224/// platforms which do not support HTML rendering, by baking the information into an image.
225///
226/// ```text
227/// <xs:element name="IconClickFallbackImages" minOccurs="0" maxOccurs="1">
228///   <xs:complexType>
229///     <xs:sequence>
230///       <xs:element name="IconClickFallbackImage" minOccurs="1" maxOccurs="unbounded">
231///     </xs:sequence>
232///   </xs:complexType>
233/// </xs:element>
234/// ```
235#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
236#[xml(tag = "IconClickFallbackImages")]
237pub struct IconClickFallbackImages<'a> {
238    /// The container for one or more [`<IconClickFallbackImage>`](IconClickFallbackImage) element.
239    #[xml(child = "IconClickFallbackImage")]
240    pub icon_click_fallback_images: Vec<IconClickFallbackImage<'a>>,
241}
242
243/// The `<IconClickFallbackImage>` element is used to display information when an icon clicka
244/// occurs.
245///
246/// ```text
247/// <xs:element name="IconClickFallbackImage">
248///   <xs:complexType>
249///     <xs:attribute name="height" type="xs:integer" use="optional">
250///     <xs:attribute name="width" type="xs:integer" use="optional">
251///     <xs:sequence>
252///       <xs:element name="AltText" minOccurs="0" maxOccurs="1" type="xs:string" >
253///       <xs:element name="StaticResource" minOccurs="0" maxOccurs="1" type="xs:anyURI">
254///     </xs:sequence>
255///   </xs:complexType>
256/// </xs:element>
257/// ```
258#[derive(hard_xml::XmlWrite, hard_xml::XmlRead, Default, PartialEq, Clone, Debug)]
259#[xml(tag = "IconClickFallbackImage")]
260pub struct IconClickFallbackImage<'a> {
261    /// Pixel height of the image asset.
262    #[xml(attr = "height", default)]
263    pub height: Option<i32>,
264    /// Pixel width of the image asset.
265    #[xml(attr = "width", default)]
266    pub width: Option<i32>,
267
268    /// The container for zero or one `<AltText>` element.
269    #[xml(flatten_text = "AltText", default)]
270    pub alt_text: Option<std::borrow::Cow<'a, str>>,
271    /// The container for zero or one `<StaticResource>` element.
272    #[xml(flatten_text = "StaticResource", cdata, default)]
273    pub static_resource: Option<std::borrow::Cow<'a, str>>,
274}