html_sys/embedded/
track.rs

1/// The HTML `<track>` element
2///
3/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track)
4#[doc(alias = "track")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct TextTrack {
8    pub data_map: crate::DataMap,
9    global_attrs: crate::GlobalAttributes,
10    /// The type of text track
11    pub kind: std::option::Option<std::borrow::Cow<'static, str>>,
12    /// Address of the resource
13    pub src: std::option::Option<std::borrow::Cow<'static, str>>,
14    /// Language of the text track
15    pub srclang: std::option::Option<std::borrow::Cow<'static, str>>,
16    /// User-visible label
17    pub label: std::option::Option<std::borrow::Cow<'static, str>>,
18    /// Enable the track if no other text track is more suitable
19    pub default: bool,
20}
21impl crate::RenderElement for TextTrack {
22    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
23        write!(writer, "<track")?;
24        if let Some(field) = self.kind.as_ref() {
25            write!(writer, r#" kind="{field}""#)?;
26        }
27        if let Some(field) = self.src.as_ref() {
28            write!(writer, r#" src="{field}""#)?;
29        }
30        if let Some(field) = self.srclang.as_ref() {
31            write!(writer, r#" srclang="{field}""#)?;
32        }
33        if let Some(field) = self.label.as_ref() {
34            write!(writer, r#" label="{field}""#)?;
35        }
36        if self.default {
37            write!(writer, r#" default"#)?;
38        }
39        write!(writer, "{}", self.global_attrs)?;
40        write!(writer, "{}", self.data_map)?;
41        write!(writer, ">")?;
42        Ok(())
43    }
44    #[allow(unused_variables)]
45    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
46        Ok(())
47    }
48}
49impl std::fmt::Display for TextTrack {
50    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51        use crate::RenderElement;
52        self.write_opening_tag(writer)?;
53        self.write_closing_tag(writer)?;
54        Ok(())
55    }
56}
57impl std::ops::Deref for TextTrack {
58    type Target = crate::GlobalAttributes;
59    fn deref(&self) -> &Self::Target {
60        &self.global_attrs
61    }
62}
63impl std::ops::DerefMut for TextTrack {
64    fn deref_mut(&mut self) -> &mut Self::Target {
65        &mut self.global_attrs
66    }
67}