Skip to content

Commit c6cdccc

Browse files
authored
feat(core)!: Lifetime API improvements in ExpandedName and QName. (#134)
1 parent 35f87c0 commit c6cdccc

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

xmlity-quick-xml/src/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl Drop for SubAttributesAccess<'_, '_> {
567567
}
568568

569569
fn key_is_declaration(key: &ExpandedName) -> bool {
570-
key.namespace() == Some(&XmlNamespace::XMLNS)
570+
*key.namespace() == Some(XmlNamespace::XMLNS)
571571
|| (key.local_name() == &LocalName::new_dangerous("xmlns") && key.namespace().is_none())
572572
}
573573

xmlity/src/lib.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,23 @@ impl<'a> ExpandedName<'a> {
136136
}
137137

138138
/// Returns the local name of this [`ExpandedName`].
139-
pub fn local_name(&self) -> &LocalName<'_> {
139+
pub fn local_name(&self) -> &LocalName<'a> {
140140
&self.local_name
141141
}
142142

143+
/// Returns a mutable reference to the local name of this [`ExpandedName`].
144+
pub fn local_name_mut(&mut self) -> &mut LocalName<'a> {
145+
&mut self.local_name
146+
}
147+
143148
/// Returns the namespace of this [`ExpandedName`].
144-
pub fn namespace(&self) -> Option<&XmlNamespace<'_>> {
145-
self.namespace.as_ref()
149+
pub fn namespace(&self) -> &Option<XmlNamespace<'a>> {
150+
&self.namespace
151+
}
152+
153+
/// Returns a mutable reference to the namespace of this [`ExpandedName`].
154+
pub fn namespace_mut(&mut self) -> &mut Option<XmlNamespace<'a>> {
155+
&mut self.namespace
146156
}
147157

148158
/// Converts this [`ExpandedName`] into a [`QName`] name using the given [`Prefix`].
@@ -210,14 +220,24 @@ impl<'a> QName<'a> {
210220
}
211221

212222
/// Returns the [`Prefix`] of this [`QName`].
213-
pub fn prefix(&self) -> Option<&Prefix<'a>> {
214-
self.prefix.as_ref()
223+
pub fn prefix(&self) -> &Option<Prefix<'a>> {
224+
&self.prefix
225+
}
226+
227+
/// Returns a mutable reference to the [`Prefix`] of this [`QName`].
228+
pub fn prefix_mut(&mut self) -> &mut Option<Prefix<'a>> {
229+
&mut self.prefix
215230
}
216231

217232
/// Returns the [`LocalName`] of this [`QName`].
218233
pub fn local_name(&self) -> &LocalName<'a> {
219234
&self.local_name
220235
}
236+
237+
/// Returns a mutable reference to the [`LocalName`] of this [`QName`].
238+
pub fn local_name_mut(&mut self) -> &mut LocalName<'a> {
239+
&mut self.local_name
240+
}
221241
}
222242

223243
impl Display for QName<'_> {
@@ -571,7 +591,7 @@ mod tests {
571591
let local_name = LocalName::from_str(local_name_text).unwrap();
572592
let expanded_name = ExpandedName::new(local_name.clone(), namespace.clone());
573593
assert_eq!(expanded_name.local_name(), &local_name);
574-
assert_eq!(expanded_name.namespace(), namespace.as_ref());
594+
assert_eq!(expanded_name.namespace(), &namespace);
575595
assert_eq!(expanded_name.to_string(), local_name_text);
576596
assert_eq!(expanded_name.into_owned().to_string(), local_name_text);
577597
}

0 commit comments

Comments
 (0)