Skip to content

Commit

Permalink
Merge pull request #416 from Mingun/helpers
Browse files Browse the repository at this point in the history
Add `<event>::borrow()` and some minor stuff
  • Loading branch information
dralley committed Jul 12, 2022
2 parents 2eecf00 + 15be5c4 commit d87eff8
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 132 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Expand Up @@ -25,6 +25,8 @@
- [#395]: Add support for XML Schema `xs:list`
- [#324]: `Reader::from_str` / `Deserializer::from_str` / `from_str` now ignore
the XML declared encoding and always use UTF-8
- [#416]: Add `borrow()` methods in all event structs which allows to get
a borrowed version of any event

### Bug Fixes

Expand Down Expand Up @@ -108,6 +110,9 @@
|`read_to_end_unbuffered` |`read_to_end`
- [#412]: Change `read_to_end*` and `read_text_into` to accept `QName` instead of `AsRef<[u8]>`

- [#416]: `BytesStart::to_borrowed` renamed to `BytesStart::borrow`, the same method
added to all events

### New Tests

- [#9]: Added tests for incorrect nested tags in input
Expand All @@ -131,6 +136,7 @@
[#403]: https://github.com/tafia/quick-xml/pull/403
[#407]: https://github.com/tafia/quick-xml/pull/407
[#412]: https://github.com/tafia/quick-xml/pull/412
[#416]: https://github.com/tafia/quick-xml/pull/416

## 0.23.0 -- 2022-05-08

Expand Down
30 changes: 24 additions & 6 deletions compare/benches/bench.rs
Expand Up @@ -25,7 +25,10 @@ fn low_level_comparison(c: &mut Criterion) {
}
buf.clear();
}
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
assert_eq!(
count, 1550,
"Overall tag count in ./tests/documents/sample_rss.xml"
);
})
});

Expand All @@ -49,7 +52,10 @@ fn low_level_comparison(c: &mut Criterion) {
}
input = &input[consumed..];
}
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
assert_eq!(
count, 1550,
"Overall tag count in ./tests/documents/sample_rss.xml"
);
})
});

Expand All @@ -68,7 +74,10 @@ fn low_level_comparison(c: &mut Criterion) {
_ => (),
}
}
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
assert_eq!(
count, 1550,
"Overall tag count in ./tests/documents/sample_rss.xml"
);
})
});

Expand All @@ -83,7 +92,10 @@ fn low_level_comparison(c: &mut Criterion) {
_ => (),
}
}
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
assert_eq!(
count, 1550,
"Overall tag count in ./tests/documents/sample_rss.xml"
);
})
});

Expand All @@ -101,7 +113,10 @@ fn low_level_comparison(c: &mut Criterion) {
_ => (),
}
}
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
assert_eq!(
count, 1550,
"Overall tag count in ./tests/documents/sample_rss.xml"
);
})
});

Expand Down Expand Up @@ -166,7 +181,10 @@ fn low_level_comparison(c: &mut Criterion) {
count += 1;
}
}
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
assert_eq!(
count, 1550,
"Overall tag count in ./tests/documents/sample_rss.xml"
);
})
});
group.finish();
Expand Down
8 changes: 4 additions & 4 deletions src/de/map.rs
Expand Up @@ -517,15 +517,15 @@ where
forward!(deserialize_any);
forward!(deserialize_ignored_any);

/// Tuple representation is the same as [sequences](#method.deserialize_seq).
/// Tuple representation is the same as [sequences](Self::deserialize_seq).
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_seq(visitor)
}

/// Named tuple representation is the same as [unnamed tuples](#method.deserialize_tuple).
/// Named tuple representation is the same as [unnamed tuples](Self::deserialize_tuple).
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
Expand Down Expand Up @@ -687,15 +687,15 @@ where
forward!(deserialize_any);
forward!(deserialize_ignored_any);

/// Representation of tuples the same as [sequences](#method.deserialize_seq).
/// Representation of tuples the same as [sequences](Self::deserialize_seq).
fn deserialize_tuple<V>(self, _len: usize, visitor: V) -> Result<V::Value, DeError>
where
V: Visitor<'de>,
{
self.deserialize_seq(visitor)
}

/// Representation of named tuples the same as [unnamed tuples](#method.deserialize_tuple).
/// Representation of named tuples the same as [unnamed tuples](Self::deserialize_tuple).
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
Expand Down
2 changes: 0 additions & 2 deletions src/errors.rs
Expand Up @@ -79,8 +79,6 @@ impl From<AttrError> for Error {
}

/// A specialized `Result` type where the error is hard-wired to [`Error`].
///
/// [`Error`]: enum.Error.html
pub type Result<T> = std::result::Result<T, Error>;

impl std::fmt::Display for Error {
Expand Down
24 changes: 11 additions & 13 deletions src/events/attributes.rs
Expand Up @@ -17,15 +17,13 @@ use std::{borrow::Cow, collections::HashMap, ops::Range};
/// want to access the value using one of the [`unescaped_value`] and [`unescape_and_decode_value`]
/// functions.
///
/// [`unescaped_value`]: #method.unescaped_value
/// [`unescape_and_decode_value`]: #method.unescape_and_decode_value
/// [`unescaped_value`]: Self::unescaped_value
/// [`unescape_and_decode_value`]: Self::unescape_and_decode_value
#[derive(Clone, PartialEq)]
pub struct Attribute<'a> {
/// The key to uniquely define the attribute.
///
/// If [`Attributes::with_checks`] is turned off, the key might not be unique.
///
/// [`Attributes::with_checks`]: struct.Attributes.html#method.with_checks
pub key: QName<'a>,
/// The raw value of the attribute.
pub value: Cow<'a, [u8]>,
Expand All @@ -39,7 +37,7 @@ impl<'a> Attribute<'a> {
///
/// This will allocate if the value contains any escape sequences.
///
/// See also [`unescaped_value_with_custom_entities()`](#method.unescaped_value_with_custom_entities)
/// See also [`unescaped_value_with_custom_entities()`](Self::unescaped_value_with_custom_entities)
pub fn unescaped_value(&self) -> XmlResult<Cow<[u8]>> {
self.make_unescaped_value(None)
}
Expand All @@ -52,7 +50,7 @@ impl<'a> Attribute<'a> {
///
/// This will allocate if the value contains any escape sequences.
///
/// See also [`unescaped_value()`](#method.unescaped_value)
/// See also [`unescaped_value()`](Self::unescaped_value)
///
/// # Pre-condition
///
Expand All @@ -76,11 +74,11 @@ impl<'a> Attribute<'a> {
/// This allocates a `String` in all cases. For performance reasons it might be a better idea to
/// instead use one of:
///
/// * [`Reader::decode()`], as it only allocates when the decoding can't be performed otherwise.
/// * [`Reader::decoder().decode()`], as it only allocates when the decoding can't be performed otherwise.
/// * [`unescaped_value()`], as it doesn't allocate when no escape sequences are used.
///
/// [`unescaped_value()`]: #method.unescaped_value
/// [`Reader::decode()`]: ../../reader/struct.Reader.html#method.decode
/// [`unescaped_value()`]: Self::unescaped_value
/// [`Reader::decoder().decode()`]: crate::reader::Decoder::decode
pub fn unescape_and_decode_value<B>(&self, reader: &Reader<B>) -> XmlResult<String> {
self.do_unescape_and_decode_value(reader, None)
}
Expand All @@ -90,11 +88,11 @@ impl<'a> Attribute<'a> {
/// This allocates a `String` in all cases. For performance reasons it might be a better idea to
/// instead use one of:
///
/// * [`Reader::decode()`], as it only allocates when the decoding can't be performed otherwise.
/// * [`Reader::decoder().decode()`], as it only allocates when the decoding can't be performed otherwise.
/// * [`unescaped_value_with_custom_entities()`], as it doesn't allocate when no escape sequences are used.
///
/// [`unescaped_value_with_custom_entities()`]: #method.unescaped_value_with_custom_entities
/// [`Reader::decode()`]: ../../reader/struct.Reader.html#method.decode
/// [`unescaped_value_with_custom_entities()`]: Self::unescaped_value_with_custom_entities
/// [`Reader::decoder().decode()`]: crate::reader::Decoder::decode
///
/// # Pre-condition
///
Expand Down Expand Up @@ -189,7 +187,7 @@ impl<'a> From<Attr<&'a [u8]>> for Attribute<'a> {
/// Yields `Result<Attribute>`. An `Err` will be yielded if an attribute is malformed or duplicated.
/// The duplicate check can be turned off by calling [`with_checks(false)`].
///
/// [`with_checks(false)`]: #method.with_checks
/// [`with_checks(false)`]: Self::with_checks
#[derive(Clone, Debug)]
pub struct Attributes<'a> {
/// slice of `Element` corresponding to attributes
Expand Down

0 comments on commit d87eff8

Please sign in to comment.