macroize Fid/Sid definitions
This commit is contained in:
parent
d3e80e3a37
commit
8567f29a50
1 changed files with 15 additions and 18 deletions
27
src/ids.rs
27
src/ids.rs
|
@ -65,27 +65,24 @@ id_def!(Qid, "entity ID", "Q", 'Q');
|
||||||
id_def!(Pid, "property ID", "P", 'P');
|
id_def!(Pid, "property ID", "P", 'P');
|
||||||
id_def!(Lid, "lexeme ID", "L", 'L');
|
id_def!(Lid, "lexeme ID", "L", 'L');
|
||||||
|
|
||||||
/// A lexeme ID and associated form ID
|
macro_rules! lexeme_subid_def {
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
|
($name:ident, $full_name:expr, $letter:expr, $khar:expr) => {
|
||||||
pub struct Fid(pub Lid, pub u16);
|
/// A lexeme ID and associated
|
||||||
|
#[doc = $full_name]
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
|
||||||
|
pub struct $name(pub Lid, pub u16);
|
||||||
|
|
||||||
/// A lexeme ID and assoicated sense ID
|
impl fmt::Display for $name {
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
|
|
||||||
pub struct Sid(pub Lid, pub u16);
|
|
||||||
|
|
||||||
impl fmt::Display for Sid {
|
|
||||||
/// Display the ID as it would be in a URI.
|
/// Display the ID as it would be in a URI.
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}-S{}", self.0, self.1)
|
write!(f, "{}-{}{}", self.0, $khar, self.1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Fid {
|
lexeme_subid_def!(Fid, "form ID", "F", 'F');
|
||||||
/// Display the ID as it would be in a URI.
|
lexeme_subid_def!(Sid, "sense ID", "S", 'S');
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "{}-F{}", self.0, self.1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod test {
|
pub mod test {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue