html_sys/embedded/
source.rs1#[doc(alias = "source")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct MediaSource {
8 pub data_map: crate::DataMap,
9 global_attrs: crate::GlobalAttributes,
10 pub type_: std::option::Option<std::borrow::Cow<'static, str>>,
12 pub media: std::option::Option<std::borrow::Cow<'static, str>>,
14 pub src: std::option::Option<std::borrow::Cow<'static, str>>,
16 pub srcset: std::option::Option<std::borrow::Cow<'static, str>>,
18 pub sizes: std::option::Option<std::borrow::Cow<'static, str>>,
20 pub width: std::option::Option<i64>,
22 pub height: std::option::Option<i64>,
24}
25impl crate::RenderElement for MediaSource {
26 fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
27 write!(writer, "<source")?;
28 if let Some(field) = self.type_.as_ref() {
29 write!(writer, r#" type="{field}""#)?;
30 }
31 if let Some(field) = self.media.as_ref() {
32 write!(writer, r#" media="{field}""#)?;
33 }
34 if let Some(field) = self.src.as_ref() {
35 write!(writer, r#" src="{field}""#)?;
36 }
37 if let Some(field) = self.srcset.as_ref() {
38 write!(writer, r#" srcset="{field}""#)?;
39 }
40 if let Some(field) = self.sizes.as_ref() {
41 write!(writer, r#" sizes="{field}""#)?;
42 }
43 if let Some(field) = self.width.as_ref() {
44 write!(writer, r#" width="{field}""#)?;
45 }
46 if let Some(field) = self.height.as_ref() {
47 write!(writer, r#" height="{field}""#)?;
48 }
49 write!(writer, "{}", self.global_attrs)?;
50 write!(writer, "{}", self.data_map)?;
51 write!(writer, ">")?;
52 Ok(())
53 }
54 #[allow(unused_variables)]
55 fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
56 Ok(())
57 }
58}
59impl std::fmt::Display for MediaSource {
60 fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 use crate::RenderElement;
62 self.write_opening_tag(writer)?;
63 self.write_closing_tag(writer)?;
64 Ok(())
65 }
66}
67impl std::ops::Deref for MediaSource {
68 type Target = crate::GlobalAttributes;
69 fn deref(&self) -> &Self::Target {
70 &self.global_attrs
71 }
72}
73impl std::ops::DerefMut for MediaSource {
74 fn deref_mut(&mut self) -> &mut Self::Target {
75 &mut self.global_attrs
76 }
77}