From ad8616aaa14ae0467813d23e5f4f8428d55d739f Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 23 Mar 2022 16:41:28 -0400 Subject: [PATCH] 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 --- tamer/src/xir/attr.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tamer/src/xir/attr.rs b/tamer/src/xir/attr.rs index 83a65015..87d029a1 100644 --- a/tamer/src/xir/attr.rs +++ b/tamer/src/xir/attr.rs @@ -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) } }