Skip to content

Commit d87eff8

Browse files
authored
Merge pull request #416 from Mingun/helpers
Add `<event>::borrow()` and some minor stuff
2 parents 2eecf00 + 15be5c4 commit d87eff8

File tree

12 files changed

+193
-132
lines changed

12 files changed

+193
-132
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
- [#395]: Add support for XML Schema `xs:list`
2626
- [#324]: `Reader::from_str` / `Deserializer::from_str` / `from_str` now ignore
2727
the XML declared encoding and always use UTF-8
28+
- [#416]: Add `borrow()` methods in all event structs which allows to get
29+
a borrowed version of any event
2830

2931
### Bug Fixes
3032

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

113+
- [#416]: `BytesStart::to_borrowed` renamed to `BytesStart::borrow`, the same method
114+
added to all events
115+
111116
### New Tests
112117

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

135141
## 0.23.0 -- 2022-05-08
136142

compare/benches/bench.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ fn low_level_comparison(c: &mut Criterion) {
2525
}
2626
buf.clear();
2727
}
28-
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
28+
assert_eq!(
29+
count, 1550,
30+
"Overall tag count in ./tests/documents/sample_rss.xml"
31+
);
2932
})
3033
});
3134

@@ -49,7 +52,10 @@ fn low_level_comparison(c: &mut Criterion) {
4952
}
5053
input = &input[consumed..];
5154
}
52-
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
55+
assert_eq!(
56+
count, 1550,
57+
"Overall tag count in ./tests/documents/sample_rss.xml"
58+
);
5359
})
5460
});
5561

@@ -68,7 +74,10 @@ fn low_level_comparison(c: &mut Criterion) {
6874
_ => (),
6975
}
7076
}
71-
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
77+
assert_eq!(
78+
count, 1550,
79+
"Overall tag count in ./tests/documents/sample_rss.xml"
80+
);
7281
})
7382
});
7483

@@ -83,7 +92,10 @@ fn low_level_comparison(c: &mut Criterion) {
8392
_ => (),
8493
}
8594
}
86-
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
95+
assert_eq!(
96+
count, 1550,
97+
"Overall tag count in ./tests/documents/sample_rss.xml"
98+
);
8799
})
88100
});
89101

@@ -101,7 +113,10 @@ fn low_level_comparison(c: &mut Criterion) {
101113
_ => (),
102114
}
103115
}
104-
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
116+
assert_eq!(
117+
count, 1550,
118+
"Overall tag count in ./tests/documents/sample_rss.xml"
119+
);
105120
})
106121
});
107122

@@ -166,7 +181,10 @@ fn low_level_comparison(c: &mut Criterion) {
166181
count += 1;
167182
}
168183
}
169-
assert_eq!(count, 1550, "Overall tag count in ./tests/documents/sample_rss.xml");
184+
assert_eq!(
185+
count, 1550,
186+
"Overall tag count in ./tests/documents/sample_rss.xml"
187+
);
170188
})
171189
});
172190
group.finish();

src/de/map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,15 @@ where
517517
forward!(deserialize_any);
518518
forward!(deserialize_ignored_any);
519519

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

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

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

698-
/// Representation of named tuples the same as [unnamed tuples](#method.deserialize_tuple).
698+
/// Representation of named tuples the same as [unnamed tuples](Self::deserialize_tuple).
699699
fn deserialize_tuple_struct<V>(
700700
self,
701701
_name: &'static str,

src/errors.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ impl From<AttrError> for Error {
7979
}
8080

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

8684
impl std::fmt::Display for Error {

src/events/attributes.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ use std::{borrow::Cow, collections::HashMap, ops::Range};
1717
/// want to access the value using one of the [`unescaped_value`] and [`unescape_and_decode_value`]
1818
/// functions.
1919
///
20-
/// [`unescaped_value`]: #method.unescaped_value
21-
/// [`unescape_and_decode_value`]: #method.unescape_and_decode_value
20+
/// [`unescaped_value`]: Self::unescaped_value
21+
/// [`unescape_and_decode_value`]: Self::unescape_and_decode_value
2222
#[derive(Clone, PartialEq)]
2323
pub struct Attribute<'a> {
2424
/// The key to uniquely define the attribute.
2525
///
2626
/// If [`Attributes::with_checks`] is turned off, the key might not be unique.
27-
///
28-
/// [`Attributes::with_checks`]: struct.Attributes.html#method.with_checks
2927
pub key: QName<'a>,
3028
/// The raw value of the attribute.
3129
pub value: Cow<'a, [u8]>,
@@ -39,7 +37,7 @@ impl<'a> Attribute<'a> {
3937
///
4038
/// This will allocate if the value contains any escape sequences.
4139
///
42-
/// See also [`unescaped_value_with_custom_entities()`](#method.unescaped_value_with_custom_entities)
40+
/// See also [`unescaped_value_with_custom_entities()`](Self::unescaped_value_with_custom_entities)
4341
pub fn unescaped_value(&self) -> XmlResult<Cow<[u8]>> {
4442
self.make_unescaped_value(None)
4543
}
@@ -52,7 +50,7 @@ impl<'a> Attribute<'a> {
5250
///
5351
/// This will allocate if the value contains any escape sequences.
5452
///
55-
/// See also [`unescaped_value()`](#method.unescaped_value)
53+
/// See also [`unescaped_value()`](Self::unescaped_value)
5654
///
5755
/// # Pre-condition
5856
///
@@ -76,11 +74,11 @@ impl<'a> Attribute<'a> {
7674
/// This allocates a `String` in all cases. For performance reasons it might be a better idea to
7775
/// instead use one of:
7876
///
79-
/// * [`Reader::decode()`], as it only allocates when the decoding can't be performed otherwise.
77+
/// * [`Reader::decoder().decode()`], as it only allocates when the decoding can't be performed otherwise.
8078
/// * [`unescaped_value()`], as it doesn't allocate when no escape sequences are used.
8179
///
82-
/// [`unescaped_value()`]: #method.unescaped_value
83-
/// [`Reader::decode()`]: ../../reader/struct.Reader.html#method.decode
80+
/// [`unescaped_value()`]: Self::unescaped_value
81+
/// [`Reader::decoder().decode()`]: crate::reader::Decoder::decode
8482
pub fn unescape_and_decode_value<B>(&self, reader: &Reader<B>) -> XmlResult<String> {
8583
self.do_unescape_and_decode_value(reader, None)
8684
}
@@ -90,11 +88,11 @@ impl<'a> Attribute<'a> {
9088
/// This allocates a `String` in all cases. For performance reasons it might be a better idea to
9189
/// instead use one of:
9290
///
93-
/// * [`Reader::decode()`], as it only allocates when the decoding can't be performed otherwise.
91+
/// * [`Reader::decoder().decode()`], as it only allocates when the decoding can't be performed otherwise.
9492
/// * [`unescaped_value_with_custom_entities()`], as it doesn't allocate when no escape sequences are used.
9593
///
96-
/// [`unescaped_value_with_custom_entities()`]: #method.unescaped_value_with_custom_entities
97-
/// [`Reader::decode()`]: ../../reader/struct.Reader.html#method.decode
94+
/// [`unescaped_value_with_custom_entities()`]: Self::unescaped_value_with_custom_entities
95+
/// [`Reader::decoder().decode()`]: crate::reader::Decoder::decode
9896
///
9997
/// # Pre-condition
10098
///
@@ -189,7 +187,7 @@ impl<'a> From<Attr<&'a [u8]>> for Attribute<'a> {
189187
/// Yields `Result<Attribute>`. An `Err` will be yielded if an attribute is malformed or duplicated.
190188
/// The duplicate check can be turned off by calling [`with_checks(false)`].
191189
///
192-
/// [`with_checks(false)`]: #method.with_checks
190+
/// [`with_checks(false)`]: Self::with_checks
193191
#[derive(Clone, Debug)]
194192
pub struct Attributes<'a> {
195193
/// slice of `Element` corresponding to attributes

0 commit comments

Comments
 (0)