2020-02-11 10:01:39 +02:00
|
|
|
use serde::{Deserialize, Serialize, Serializer};
|
2024-11-05 04:22:32 +02:00
|
|
|
use std::io::Write;
|
2020-02-11 10:01:39 +02:00
|
|
|
|
2019-12-04 09:28:11 +02:00
|
|
|
use crate::documents::BuildXML;
|
|
|
|
use crate::xml_builder::*;
|
|
|
|
|
2020-02-11 10:01:39 +02:00
|
|
|
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
2019-12-04 09:28:11 +02:00
|
|
|
pub struct Underline {
|
2025-05-02 15:28:08 +03:00
|
|
|
pub val: String,
|
2019-12-04 09:28:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Underline {
|
|
|
|
pub fn new(val: impl Into<String>) -> Underline {
|
|
|
|
Underline { val: val.into() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BuildXML for Underline {
|
2024-11-05 04:22:32 +02:00
|
|
|
fn build_to<W: Write>(
|
|
|
|
&self,
|
|
|
|
stream: xml::writer::EventWriter<W>,
|
|
|
|
) -> xml::writer::Result<xml::writer::EventWriter<W>> {
|
|
|
|
XMLBuilder::from(stream).underline(&self.val)?.into_inner()
|
2019-12-04 09:28:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 10:01:39 +02:00
|
|
|
impl Serialize for Underline {
|
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
{
|
|
|
|
serializer.serialize_str(&self.val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-04 09:28:11 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
#[cfg(test)]
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_underline() {
|
|
|
|
let c = Underline::new("single");
|
|
|
|
let b = c.build();
|
|
|
|
assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:u w:val="single" />"#);
|
|
|
|
}
|
|
|
|
}
|