From 9472fe95fda55160bdd5a3720f0a96c38223f5f4 Mon Sep 17 00:00:00 2001 From: Marco Rebhan Date: Wed, 21 Feb 2024 15:06:56 +0100 Subject: [PATCH] Don't unnecessarily restrict create_element to borrowed names --- Changelog.md | 5 ++++- fuzz/fuzz_targets/structured_roundtrip.rs | 2 +- src/writer.rs | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index 35c405a5..666bcf85 100644 --- a/Changelog.md +++ b/Changelog.md @@ -30,7 +30,9 @@ to get an offset of the error position. For `SyntaxError`s the range - [#362]: Added `BytesCData::minimal_escape()` which escapes only `&` and `<`. - [#362]: Added `Serializer::set_quote_level()` which allow to set desired level of escaping. - [#705]: Added `NsReader::prefixes()` to list all the prefixes currently declared. -- [#629]: Added a default case to `impl_deserialize_for_internally_tagged_enum` macro so that it can handle every attribute that does not match existing cases within an enum variant. +- [#629]: Added a default case to `impl_deserialize_for_internally_tagged_enum` macro so that + it can handle every attribute that does not match existing cases within an enum variant. +- [#722]: Allow to pass owned strings to `Writer::create_element`. This is breaking change! ### Bug Fixes @@ -74,6 +76,7 @@ to get an offset of the error position. For `SyntaxError`s the range [#689]: https://github.com/tafia/quick-xml/pull/689 [#704]: https://github.com/tafia/quick-xml/pull/704 [#705]: https://github.com/tafia/quick-xml/pull/705 +[#722]: https://github.com/tafia/quick-xml/pull/722 [#738]: https://github.com/tafia/quick-xml/pull/738 diff --git a/fuzz/fuzz_targets/structured_roundtrip.rs b/fuzz/fuzz_targets/structured_roundtrip.rs index 26eec825..f0cc6ee9 100644 --- a/fuzz/fuzz_targets/structured_roundtrip.rs +++ b/fuzz/fuzz_targets/structured_roundtrip.rs @@ -60,7 +60,7 @@ fn fuzz_round_trip(driver: Driver) -> quick_xml::Result<()> { attributes, } => { let element_writer = writer - .create_element(&name) + .create_element(name) .with_attributes(attributes.into_iter().copied()); use ElementWriterFunc::*; match func { diff --git a/src/writer.rs b/src/writer.rs index 122eb488..2d455c46 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -1,5 +1,6 @@ //! Contains high-level interface for an events-based XML emitter. +use std::borrow::Cow; use std::io::Write; use std::result::Result as StdResult; @@ -143,13 +144,13 @@ impl Writer { /// # } /// ``` #[must_use] - pub fn create_element<'a, N>(&'a mut self, name: &'a N) -> ElementWriter + pub fn create_element<'a, N>(&'a mut self, name: N) -> ElementWriter where - N: 'a + AsRef + ?Sized, + N: Into>, { ElementWriter { writer: self, - start_tag: BytesStart::new(name.as_ref()), + start_tag: BytesStart::new(name), } } }