diff --git a/Changelog.md b/Changelog.md index 4b57c10f..4080b39e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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 diff --git a/src/escapei.rs b/src/escapei.rs index ce779f09..7ca5da46 100644 --- a/src/escapei.rs +++ b/src/escapei.rs @@ -159,11 +159,11 @@ pub fn unescape(raw: &str) -> Result, 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, 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; diff --git a/src/events/attributes.rs b/src/events/attributes.rs index 8c99b8b7..2b109aa9 100644 --- a/src/events/attributes.rs +++ b/src/events/attributes.rs @@ -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> { // from_utf8 should never fail because content is always UTF-8 encoded let decoded = match &self.value { @@ -91,7 +91,7 @@ impl<'a> Attribute<'a> { pub fn decode_and_unescape_value_with<'entity, B>( &self, reader: &Reader, - resolve_entity: impl Fn(&str) -> Option<&'entity str>, + resolve_entity: impl FnMut(&str) -> Option<&'entity str>, ) -> XmlResult> { let decoded = match &self.value { Cow::Borrowed(bytes) => reader.decoder().decode(bytes)?, diff --git a/src/events/mod.rs b/src/events/mod.rs index 491ce69d..b5480dee 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs @@ -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> { let decoded = match &self.content { Cow::Borrowed(bytes) => self.decoder.decode(bytes)?,