docx_rs/documents/elements/
underline.rs1use serde::{Deserialize, Serialize, Serializer};
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::xml_builder::*;
6
7#[derive(Debug, Clone, Deserialize, PartialEq)]
8pub struct Underline {
9 val: String,
10}
11
12impl Underline {
13 pub fn new(val: impl Into<String>) -> Underline {
14 Underline { val: val.into() }
15 }
16}
17
18impl BuildXML for Underline {
19 fn build_to<W: Write>(
20 &self,
21 stream: xml::writer::EventWriter<W>,
22 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
23 XMLBuilder::from(stream).underline(&self.val)?.into_inner()
24 }
25}
26
27impl Serialize for Underline {
28 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
29 where
30 S: Serializer,
31 {
32 serializer.serialize_str(&self.val)
33 }
34}
35
36#[cfg(test)]
37mod tests {
38
39 use super::*;
40 #[cfg(test)]
41 use pretty_assertions::assert_eq;
42 use std::str;
43
44 #[test]
45 fn test_underline() {
46 let c = Underline::new("single");
47 let b = c.build();
48 assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:u w:val="single" />"#);
49 }
50}