html_sys/metadata/
base.rs

1/// The HTML `<base>` element
2///
3/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base)
4#[doc(alias = "base")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct Base {
8    pub data_map: crate::DataMap,
9    global_attrs: crate::GlobalAttributes,
10    /// Document base URL
11    pub href: std::option::Option<std::borrow::Cow<'static, str>>,
12    /// Default navigable for hyperlink navigation and form submission
13    pub target: std::option::Option<std::borrow::Cow<'static, str>>,
14}
15impl crate::RenderElement for Base {
16    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
17        write!(writer, "<base")?;
18        if let Some(field) = self.href.as_ref() {
19            write!(writer, r#" href="{field}""#)?;
20        }
21        if let Some(field) = self.target.as_ref() {
22            write!(writer, r#" target="{field}""#)?;
23        }
24        write!(writer, "{}", self.global_attrs)?;
25        write!(writer, "{}", self.data_map)?;
26        write!(writer, ">")?;
27        Ok(())
28    }
29    #[allow(unused_variables)]
30    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
31        Ok(())
32    }
33}
34impl std::fmt::Display for Base {
35    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        use crate::RenderElement;
37        self.write_opening_tag(writer)?;
38        self.write_closing_tag(writer)?;
39        Ok(())
40    }
41}
42impl std::ops::Deref for Base {
43    type Target = crate::GlobalAttributes;
44    fn deref(&self) -> &Self::Target {
45        &self.global_attrs
46    }
47}
48impl std::ops::DerefMut for Base {
49    fn deref_mut(&mut self) -> &mut Self::Target {
50        &mut self.global_attrs
51    }
52}