tamer: xir::attr::Attr: Convert to tuple struct with public fields

This makes more sense for pattern matching.  Encapsulation of these fields
is not necessary, given that it's passed around as an owned value and its
`new` method constructs it verbatim; the individual fields are
self-validating.

DEV-10863
main
Mike Gerwitz 2022-03-23 16:41:28 -04:00
parent fbf786086a
commit ad8616aaa1
1 changed files with 6 additions and 11 deletions

View File

@ -33,25 +33,20 @@ pub use parse::{AttrParseError, AttrParseState};
/// Element attribute.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Attr {
name: QName,
value: SymbolId,
/// Spans for the attribute name and value respectively.
span: (Span, Span),
}
pub struct Attr(pub QName, pub SymbolId, pub (Span, Span));
impl Attr {
/// Construct a new simple attribute with a name, value, and respective
/// [`Span`]s.
#[inline]
pub fn new(name: QName, value: SymbolId, span: (Span, Span)) -> Self {
Self { name, value, span }
Self(name, value, span)
}
/// Attribute name.
#[inline]
pub fn name(&self) -> QName {
self.name
self.0
}
/// Retrieve the value from the attribute.
@ -60,7 +55,7 @@ impl Attr {
/// this returns an owned value.
#[inline]
pub fn value(&self) -> SymbolId {
self.value
self.1
}
}
@ -69,13 +64,13 @@ impl Token for Attr {
// TODO: This may or may not actually represent the span relative to
// a given parser,
// so we may want to accept a context to bias toward.
self.span.1
self.2 .1
}
}
impl Display for Attr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "`@{}=\"{}\"` at {}", self.name, self.value, self.span.0)
write!(f, "`@{}=\"{}\"` at {}", self.0, self.1, self.2 .0)
}
}