use std::fmt;
use serde::{Deserialize, Serialize};
use crate::link::Locator;
#[derive(PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize)]
pub enum Type {
TitleAuto,
TitleManual,
Direct,
ElementId,
}
impl fmt::Display for Type {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::TitleAuto => write!(f, "title-auto"),
Self::TitleManual => write!(f, "title-manual"),
Self::Direct => write!(f, "direct"),
Self::ElementId => write!(f, "element-id"),
}
}
}
#[derive(PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct Anchor {
pub source: Locator,
pub name: String,
pub r#type: Type,
}
impl fmt::Debug for Anchor {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}#{} (type {:#?})", self.source, self.name, self.r#type)
}
}
impl fmt::Display for Anchor {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}#{}", self.source, self.name)
}
}