docx_reader/documents/elements/
instr_hyperlink.rsuse serde::Serialize;
#[derive(Serialize, Debug, Clone, PartialEq, Default)]
#[serde(rename_all = "camelCase")]
pub struct InstrHyperlink {
pub target: String,
pub anchor: bool,
}
impl InstrHyperlink {
pub fn new(target: impl Into<String>) -> Self {
Self {
target: target.into(),
..Default::default()
}
}
}
impl std::str::FromStr for InstrHyperlink {
type Err = ();
fn from_str(instr: &str) -> Result<Self, Self::Err> {
let mut s = instr.split(' ');
let mut target = "".to_string();
let mut anchor = false;
loop {
if let Some(i) = s.next() {
match i {
"\\l" => {
anchor = true;
}
"\\m" => {
}
"\\n" => {
}
"\\o" => {
let _ = s.next();
}
"\\t" => {
let _ = s.next();
}
_ => {
target = i.replace(""", "").replace("\"", "").to_string();
}
}
} else {
if target.is_empty() {
return Err(());
}
return Ok(Self { target, anchor });
}
}
}
}