docx_rs/documents/elements/
link.rs1use serde::{Serialize, Serializer};
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::escape::escape;
6use crate::xml_builder::*;
7
8#[derive(Debug, Clone, PartialEq)]
9pub struct Link {
10 val: String,
11}
12
13impl Link {
14 pub fn new(val: impl Into<String>) -> Link {
15 Link {
16 val: escape(&val.into()),
17 }
18 }
19}
20
21impl Serialize for Link {
22 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
23 where
24 S: Serializer,
25 {
26 serializer.serialize_str(&self.val)
27 }
28}
29
30impl BuildXML for Link {
31 fn build_to<W: Write>(
32 &self,
33 stream: xml::writer::EventWriter<W>,
34 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
35 XMLBuilder::from(stream).link(&self.val)?.into_inner()
36 }
37}