tamer: ir::xir::{QName, Prefix, LocalName}: Implement Display

These will be shown in error messages and need user-friendly
representations.

DEV-10863
main
Mike Gerwitz 2021-11-02 13:55:33 -04:00
parent d045786cfb
commit edf9a75575
1 changed files with 22 additions and 0 deletions

View File

@ -72,6 +72,7 @@ use crate::sym::{
};
use memchr::memchr;
use std::convert::{TryFrom, TryInto};
use std::fmt::Display;
use std::ops::Deref;
mod error;
@ -262,6 +263,18 @@ impl TryFrom<&str> for LocalPart {
}
}
impl Display for Prefix {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl Display for LocalPart {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
/// A sequence of one or more whitespace characters.
///
/// Whitespace here is expected to consist of `[ \n\t\r]`
@ -431,6 +444,15 @@ impl TryFrom<&[u8]> for QName {
}
}
impl Display for QName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
QName(Some(local), suffix) => write!(f, "{}:{}", local, suffix),
QName(None, suffix) => suffix.fmt(f),
}
}
}
/// Represents text and its escaped state.
///
/// Being explicit about the state of escaping allows us to skip checks when