Skip to content

Commit

Permalink
Return AttrError from attribute methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RedPhoenixQ committed Oct 1, 2024
1 parent da8fb10 commit 4bbb94b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
- [#810]: Return `std::io::Error` from `Writer` methods.
- [#811]: Split `NamespaceError` and `EncodingError` from `Error`.
- [#811]: Renamed `Error::EscapeError` to `Error::Escape` to match other variants.
- [#811]: `Bangtype` returns `SyntaxError` instead of `Error` since no other variant of `Error` is possible.
- [#811]: Narrow down error return type from `Error` where only one variant is ever returned:
- `Bangtype` methods returns `SyntaxError`
- attribute related methods on `BytesStart` and `BytesDecl` returns `AttrError`

[#227]: https://github.com/tafia/quick-xml/issues/227
[#810]: https://github.com/tafia/quick-xml/pull/810
Expand Down
8 changes: 4 additions & 4 deletions src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::name::{LocalName, QName};
#[cfg(feature = "serialize")]
use crate::utils::CowRef;
use crate::utils::{name_len, trim_xml_end, trim_xml_start, write_cow_string};
use attributes::{Attribute, Attributes};
use attributes::{AttrError, Attribute, Attributes};

/// Opening tag data (`Event::Start`), with optional attributes: `<name attr="value">`.
///
Expand Down Expand Up @@ -297,7 +297,7 @@ impl<'a> BytesStart<'a> {
pub fn try_get_attribute<N: AsRef<[u8]> + Sized>(
&'a self,
attr_name: N,
) -> Result<Option<Attribute<'a>>, Error> {
) -> Result<Option<Attribute<'a>>, AttrError> {
for a in self.attributes().with_checks(false) {
let a = a?;
if a.key.as_ref() == attr_name.as_ref() {
Expand Down Expand Up @@ -1189,7 +1189,7 @@ impl<'a> BytesDecl<'a> {
/// ```
///
/// [grammar]: https://www.w3.org/TR/xml11/#NT-XMLDecl
pub fn encoding(&self) -> Option<Result<Cow<[u8]>, Error>> {
pub fn encoding(&self) -> Option<Result<Cow<[u8]>, AttrError>> {
self.content
.try_get_attribute("encoding")
.map(|a| a.map(|a| a.value))
Expand Down Expand Up @@ -1231,7 +1231,7 @@ impl<'a> BytesDecl<'a> {
/// ```
///
/// [grammar]: https://www.w3.org/TR/xml11/#NT-XMLDecl
pub fn standalone(&self) -> Option<Result<Cow<[u8]>, Error>> {
pub fn standalone(&self) -> Option<Result<Cow<[u8]>, AttrError>> {
self.content
.try_get_attribute("standalone")
.map(|a| a.map(|a| a.value))
Expand Down

0 comments on commit 4bbb94b

Please sign in to comment.