use hard_xml::{XmlRead, XmlWrite};
use std::borrow::Cow;
use crate::{__string_enum, __xml_test_suites};
#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:instrText")]
pub struct InstrText<'a> {
#[xml(attr = "xml:space")]
pub space: Option<TextSpace>,
#[xml(text)]
pub text: Cow<'a, str>,
}
impl From<String> for InstrText<'_> {
fn from(val: String) -> Self {
InstrText {
text: val.into(),
space: None,
}
}
}
impl<'a> From<&'a str> for InstrText<'a> {
fn from(val: &'a str) -> Self {
InstrText {
text: val.into(),
space: None,
}
}
}
impl From<(String, TextSpace)> for InstrText<'_> {
fn from(val: (String, TextSpace)) -> Self {
InstrText {
text: val.0.into(),
space: Some(val.1),
}
}
}
impl<'a> From<(&'a str, TextSpace)> for InstrText<'a> {
fn from(val: (&'a str, TextSpace)) -> Self {
InstrText {
text: val.0.into(),
space: Some(val.1),
}
}
}
#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:delInstrText")]
pub struct DelInstrText<'a> {
#[xml(attr = "xml:space")]
pub space: Option<TextSpace>,
#[xml(text)]
pub text: Cow<'a, str>,
}
impl From<String> for DelInstrText<'_> {
fn from(val: String) -> Self {
DelInstrText {
text: val.into(),
space: None,
}
}
}
impl<'a> From<&'a str> for DelInstrText<'a> {
fn from(val: &'a str) -> Self {
DelInstrText {
text: val.into(),
space: None,
}
}
}
impl From<(String, TextSpace)> for DelInstrText<'_> {
fn from(val: (String, TextSpace)) -> Self {
DelInstrText {
text: val.0.into(),
space: Some(val.1),
}
}
}
impl<'a> From<(&'a str, TextSpace)> for DelInstrText<'a> {
fn from(val: (&'a str, TextSpace)) -> Self {
DelInstrText {
text: val.0.into(),
space: Some(val.1),
}
}
}
#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
pub enum TextSpace {
Default,
Preserve,
}
__string_enum! {
TextSpace {
Default = "default",
Preserve = "preserve",
}
}
__xml_test_suites!(
InstrText,
InstrText::from("text"),
"<w:instrText>text</w:instrText>",
InstrText::from(String::from("text")),
"<w:instrText>text</w:instrText>",
InstrText::from(("text", TextSpace::Preserve)),
r#"<w:instrText xml:space="preserve">text</w:instrText>"#,
InstrText::from((String::from("text"), TextSpace::Default)),
r#"<w:instrText xml:space="default">text</w:instrText>"#,
);