Skip to content

Commit 4bbb94b

Browse files
committed
Return AttrError from attribute methods
1 parent da8fb10 commit 4bbb94b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
- [#810]: Return `std::io::Error` from `Writer` methods.
2525
- [#811]: Split `NamespaceError` and `EncodingError` from `Error`.
2626
- [#811]: Renamed `Error::EscapeError` to `Error::Escape` to match other variants.
27-
- [#811]: `Bangtype` returns `SyntaxError` instead of `Error` since no other variant of `Error` is possible.
27+
- [#811]: Narrow down error return type from `Error` where only one variant is ever returned:
28+
- `Bangtype` methods returns `SyntaxError`
29+
- attribute related methods on `BytesStart` and `BytesDecl` returns `AttrError`
2830

2931
[#227]: https://github.com/tafia/quick-xml/issues/227
3032
[#810]: https://github.com/tafia/quick-xml/pull/810

src/events/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use crate::name::{LocalName, QName};
5454
#[cfg(feature = "serialize")]
5555
use crate::utils::CowRef;
5656
use crate::utils::{name_len, trim_xml_end, trim_xml_start, write_cow_string};
57-
use attributes::{Attribute, Attributes};
57+
use attributes::{AttrError, Attribute, Attributes};
5858

5959
/// Opening tag data (`Event::Start`), with optional attributes: `<name attr="value">`.
6060
///
@@ -297,7 +297,7 @@ impl<'a> BytesStart<'a> {
297297
pub fn try_get_attribute<N: AsRef<[u8]> + Sized>(
298298
&'a self,
299299
attr_name: N,
300-
) -> Result<Option<Attribute<'a>>, Error> {
300+
) -> Result<Option<Attribute<'a>>, AttrError> {
301301
for a in self.attributes().with_checks(false) {
302302
let a = a?;
303303
if a.key.as_ref() == attr_name.as_ref() {
@@ -1189,7 +1189,7 @@ impl<'a> BytesDecl<'a> {
11891189
/// ```
11901190
///
11911191
/// [grammar]: https://www.w3.org/TR/xml11/#NT-XMLDecl
1192-
pub fn encoding(&self) -> Option<Result<Cow<[u8]>, Error>> {
1192+
pub fn encoding(&self) -> Option<Result<Cow<[u8]>, AttrError>> {
11931193
self.content
11941194
.try_get_attribute("encoding")
11951195
.map(|a| a.map(|a| a.value))
@@ -1231,7 +1231,7 @@ impl<'a> BytesDecl<'a> {
12311231
/// ```
12321232
///
12331233
/// [grammar]: https://www.w3.org/TR/xml11/#NT-XMLDecl
1234-
pub fn standalone(&self) -> Option<Result<Cow<[u8]>, Error>> {
1234+
pub fn standalone(&self) -> Option<Result<Cow<[u8]>, AttrError>> {
12351235
self.content
12361236
.try_get_attribute("standalone")
12371237
.map(|a| a.map(|a| a.value))

0 commit comments

Comments
 (0)