html_sys/metadata/
link.rs

1/// The HTML `<link>` element
2///
3/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
4#[doc(alias = "link")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct Link {
8    pub data_map: crate::DataMap,
9    global_attrs: crate::GlobalAttributes,
10    /// Address of the hyperlink
11    pub href: std::option::Option<std::borrow::Cow<'static, str>>,
12    /// How the element handles crossorigin requests
13    pub crossorigin: std::option::Option<std::borrow::Cow<'static, str>>,
14    /// Relationship between the document containing the hyperlink and the destination resource
15    pub rel: std::option::Option<std::borrow::Cow<'static, str>>,
16    /// Applicable media
17    pub media: std::option::Option<std::borrow::Cow<'static, str>>,
18    /// Integrity metadata used in Subresource Integrity checks [SRI]
19    pub integrity: std::option::Option<std::borrow::Cow<'static, str>>,
20    /// Language of the linked resource
21    pub hreflang: std::option::Option<std::borrow::Cow<'static, str>>,
22    /// Hint for the type of the referenced resource
23    pub type_: std::option::Option<std::borrow::Cow<'static, str>>,
24    /// Referrer policy for fetches initiated by the element
25    pub referrerpolicy: std::option::Option<std::borrow::Cow<'static, str>>,
26    /// Sizes of the icons (for rel="icon")
27    pub sizes: std::option::Option<std::borrow::Cow<'static, str>>,
28    /// Images to use in different situations, e.g., high-resolution displays, small monitors, etc. (for rel="preload")
29    pub imagesrcset: std::option::Option<std::borrow::Cow<'static, str>>,
30    /// Image sizes for different page layouts (for rel="preload")
31    pub imagesizes: std::option::Option<std::borrow::Cow<'static, str>>,
32    /// Potential destination for a preload request (for rel="preload" and rel="modulepreload")
33    pub as_: std::option::Option<std::borrow::Cow<'static, str>>,
34    /// Whether the element is potentially render-blocking
35    pub blocking: std::option::Option<std::borrow::Cow<'static, str>>,
36    /// Color to use when customizing a site's icon (for rel="mask-icon")
37    pub color: std::option::Option<std::borrow::Cow<'static, str>>,
38    /// Whether the link is disabled
39    pub disabled: std::option::Option<std::borrow::Cow<'static, str>>,
40    /// Sets the priority for fetches initiated by the element
41    pub fetchpriority: std::option::Option<std::borrow::Cow<'static, str>>,
42}
43impl crate::RenderElement for Link {
44    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
45        write!(writer, "<link")?;
46        if let Some(field) = self.href.as_ref() {
47            write!(writer, r#" href="{field}""#)?;
48        }
49        if let Some(field) = self.crossorigin.as_ref() {
50            write!(writer, r#" crossorigin="{field}""#)?;
51        }
52        if let Some(field) = self.rel.as_ref() {
53            write!(writer, r#" rel="{field}""#)?;
54        }
55        if let Some(field) = self.media.as_ref() {
56            write!(writer, r#" media="{field}""#)?;
57        }
58        if let Some(field) = self.integrity.as_ref() {
59            write!(writer, r#" integrity="{field}""#)?;
60        }
61        if let Some(field) = self.hreflang.as_ref() {
62            write!(writer, r#" hreflang="{field}""#)?;
63        }
64        if let Some(field) = self.type_.as_ref() {
65            write!(writer, r#" type="{field}""#)?;
66        }
67        if let Some(field) = self.referrerpolicy.as_ref() {
68            write!(writer, r#" referrerpolicy="{field}""#)?;
69        }
70        if let Some(field) = self.sizes.as_ref() {
71            write!(writer, r#" sizes="{field}""#)?;
72        }
73        if let Some(field) = self.imagesrcset.as_ref() {
74            write!(writer, r#" imagesrcset="{field}""#)?;
75        }
76        if let Some(field) = self.imagesizes.as_ref() {
77            write!(writer, r#" imagesizes="{field}""#)?;
78        }
79        if let Some(field) = self.as_.as_ref() {
80            write!(writer, r#" as="{field}""#)?;
81        }
82        if let Some(field) = self.blocking.as_ref() {
83            write!(writer, r#" blocking="{field}""#)?;
84        }
85        if let Some(field) = self.color.as_ref() {
86            write!(writer, r#" color="{field}""#)?;
87        }
88        if let Some(field) = self.disabled.as_ref() {
89            write!(writer, r#" disabled="{field}""#)?;
90        }
91        if let Some(field) = self.fetchpriority.as_ref() {
92            write!(writer, r#" fetchpriority="{field}""#)?;
93        }
94        write!(writer, "{}", self.global_attrs)?;
95        write!(writer, "{}", self.data_map)?;
96        write!(writer, ">")?;
97        Ok(())
98    }
99    #[allow(unused_variables)]
100    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
101        Ok(())
102    }
103}
104impl std::fmt::Display for Link {
105    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
106        use crate::RenderElement;
107        self.write_opening_tag(writer)?;
108        self.write_closing_tag(writer)?;
109        Ok(())
110    }
111}
112impl std::ops::Deref for Link {
113    type Target = crate::GlobalAttributes;
114    fn deref(&self) -> &Self::Target {
115        &self.global_attrs
116    }
117}
118impl std::ops::DerefMut for Link {
119    fn deref_mut(&mut self) -> &mut Self::Target {
120        &mut self.global_attrs
121    }
122}