Skip to content

Commit

Permalink
Change unescape_ functions from Fn to FnMut.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigeonhands authored and Mingun committed Apr 8, 2023
1 parent 76996ab commit b2ceae7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
### Misc Changes

- [#584]: Export `EscapeError` from the crate
- [#581]: Relax requirements for `unsescape_*` set of functions -- their now use
`FnMut` instead of `Fn` for `resolve_entity` parameters, like `Iterator::map`
from `std`.

[#581]: https://github.com/tafia/quick-xml/pull/581
[#584]: https://github.com/tafia/quick-xml/pull/584


Expand Down
4 changes: 2 additions & 2 deletions src/escapei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ pub fn unescape(raw: &str) -> Result<Cow<str>, EscapeError> {
/// [HTML5 escapes]: https://dev.w3.org/html5/html-author/charref
pub fn unescape_with<'input, 'entity, F>(
raw: &'input str,
resolve_entity: F,
mut resolve_entity: F,
) -> Result<Cow<'input, str>, EscapeError>
where
// the lifetime of the output comes from a capture or is `'static`
F: Fn(&str) -> Option<&'entity str>,
F: FnMut(&str) -> Option<&'entity str>,
{
let bytes = raw.as_bytes();
let mut unescaped = None;
Expand Down
4 changes: 2 additions & 2 deletions src/events/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'a> Attribute<'a> {
#[cfg(any(doc, not(feature = "encoding")))]
pub fn unescape_value_with<'entity>(
&self,
resolve_entity: impl Fn(&str) -> Option<&'entity str>,
resolve_entity: impl FnMut(&str) -> Option<&'entity str>,
) -> XmlResult<Cow<'a, str>> {
// from_utf8 should never fail because content is always UTF-8 encoded
let decoded = match &self.value {
Expand Down Expand Up @@ -91,7 +91,7 @@ impl<'a> Attribute<'a> {
pub fn decode_and_unescape_value_with<'entity, B>(
&self,
reader: &Reader<B>,
resolve_entity: impl Fn(&str) -> Option<&'entity str>,
resolve_entity: impl FnMut(&str) -> Option<&'entity str>,
) -> XmlResult<Cow<'a, str>> {
let decoded = match &self.value {
Cow::Borrowed(bytes) => reader.decoder().decode(bytes)?,
Expand Down
2 changes: 1 addition & 1 deletion src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ impl<'a> BytesText<'a> {
/// non-UTF-8 encoding.
pub fn unescape_with<'entity>(
&self,
resolve_entity: impl Fn(&str) -> Option<&'entity str>,
resolve_entity: impl FnMut(&str) -> Option<&'entity str>,
) -> Result<Cow<'a, str>> {
let decoded = match &self.content {
Cow::Borrowed(bytes) => self.decoder.decode(bytes)?,
Expand Down

0 comments on commit b2ceae7

Please sign in to comment.