Skip to content

Conversation

@lukasfri
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings January 15, 2026 22:05
@lukasfri lukasfri added the enhancement New feature or request label Jan 15, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds two convenience methods to the XmlRoot<T> type to make it easier to extract the first value element from an XML document.

Changes:

  • Added value() method to get a reference to the first value element
  • Added into_value() method to consume the XmlRoot and return the first value element
  • Added a working example demonstrating the usage of these new methods

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
xmlity/src/types/utils.rs Implements value() and into_value() methods for XmlRoot<T> to extract the first value element
xmlity-quick-xml/examples/xml_root.rs Adds an example demonstrating how to use the new into_value() method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +287 to +304
self.elements.iter().find_map(|e| {
if let XmlRootTop::Value(v) = e {
Some(v)
} else {
None
}
})
}

/// Consumes the XML document and returns the first value element, if any.
pub fn into_value(self) -> Option<T> {
self.elements.into_iter().find_map(|e| {
if let XmlRootTop::Value(v) = e {
Some(v)
} else {
None
}
})
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern matching can be simplified using matches! or a closure shorthand. The else { None } branch is redundant with find_map since non-matching items naturally return None. Consider using: self.elements.iter().find_map(|e| match e { XmlRootTop::Value(v) => Some(v), _ => None }) or even simpler: self.elements.iter().find_map(|e| if let XmlRootTop::Value(v) = e { Some(v) } else { None }).

Suggested change
self.elements.iter().find_map(|e| {
if let XmlRootTop::Value(v) = e {
Some(v)
} else {
None
}
})
}
/// Consumes the XML document and returns the first value element, if any.
pub fn into_value(self) -> Option<T> {
self.elements.into_iter().find_map(|e| {
if let XmlRootTop::Value(v) = e {
Some(v)
} else {
None
}
})
self.elements
.iter()
.find_map(|e| match e {
XmlRootTop::Value(v) => Some(v),
_ => None,
})
}
/// Consumes the XML document and returns the first value element, if any.
pub fn into_value(self) -> Option<T> {
self.elements
.into_iter()
.find_map(|e| match e {
XmlRootTop::Value(v) => Some(v),
_ => None,
})

Copilot uses AI. Check for mistakes.
Comment on lines +287 to +304
self.elements.iter().find_map(|e| {
if let XmlRootTop::Value(v) = e {
Some(v)
} else {
None
}
})
}

/// Consumes the XML document and returns the first value element, if any.
pub fn into_value(self) -> Option<T> {
self.elements.into_iter().find_map(|e| {
if let XmlRootTop::Value(v) = e {
Some(v)
} else {
None
}
})
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the value() method, this pattern matching can be simplified. The explicit else { None } branch is redundant with find_map semantics.

Suggested change
self.elements.iter().find_map(|e| {
if let XmlRootTop::Value(v) = e {
Some(v)
} else {
None
}
})
}
/// Consumes the XML document and returns the first value element, if any.
pub fn into_value(self) -> Option<T> {
self.elements.into_iter().find_map(|e| {
if let XmlRootTop::Value(v) = e {
Some(v)
} else {
None
}
})
for e in &self.elements {
if let XmlRootTop::Value(v) = e {
return Some(v);
}
}
None
}
/// Consumes the XML document and returns the first value element, if any.
pub fn into_value(self) -> Option<T> {
for e in self.elements {
if let XmlRootTop::Value(v) = e {
return Some(v);
}
}
None

Copilot uses AI. Check for mistakes.
@lukasfri lukasfri merged commit 31a9993 into main Jan 15, 2026
12 checks passed
@lukasfri lukasfri deleted the feat/xml-root-value-methods branch January 15, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants