tamer: ir::xir::{QName, Prefix, LocalName}: Implement Display
These will be shown in error messages and need user-friendly representations. DEV-10863main
parent
d045786cfb
commit
edf9a75575
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue