diff --git a/Changelog.md b/Changelog.md index 60b2b965..c5234e6b 100644 --- a/Changelog.md +++ b/Changelog.md @@ -95,6 +95,8 @@ Use methods on `Attribute` instead - [#403]: Remove deprecated `quick_xml::de::from_bytes` and `Deserializer::from_borrowing_reader` +- [#413]: Removed the `Attribute::from((&[u8], &[u8]))` implementation, use + `Attribute::new(&[u8], &[u8])` instead. ### New Tests @@ -117,6 +119,7 @@ [#395]: https://github.com/tafia/quick-xml/pull/395 [#403]: https://github.com/tafia/quick-xml/pull/403 [#407]: https://github.com/tafia/quick-xml/pull/407 +[#413]: https://github.com/tafia/quick-xml/pull/413 ## 0.23.0 -- 2022-05-08 diff --git a/src/events/attributes.rs b/src/events/attributes.rs index d6331bc7..e4aa1b60 100644 --- a/src/events/attributes.rs +++ b/src/events/attributes.rs @@ -32,6 +32,25 @@ pub struct Attribute<'a> { } impl<'a> Attribute<'a> { + /// Creates new attribute from raw bytes. + /// Does not apply any transformation to either key or value. + /// + /// # Examples + /// + /// ``` + /// # use pretty_assertions::assert_eq; + /// use quick_xml::events::attributes::Attribute; + /// + /// let features = Attribute::new("features".as_bytes(), "Bells & whistles".as_bytes()); + /// assert_eq!(features.value, "Bells & whistles".as_bytes()); + /// ``` + pub fn new(name: &'a [u8], val: &'a [u8]) -> Attribute<'a> { + Attribute { + key: QName(name), + value: Cow::from(val), + } + } + /// Returns the unescaped value. /// /// This is normally the value you are interested in. Escape sequences such as `>` are @@ -130,27 +149,6 @@ impl<'a> Debug for Attribute<'a> { } } -impl<'a> From<(&'a [u8], &'a [u8])> for Attribute<'a> { - /// Creates new attribute from raw bytes. - /// Does not apply any transformation to both key and value. - /// - /// # Examples - /// - /// ``` - /// # use pretty_assertions::assert_eq; - /// use quick_xml::events::attributes::Attribute; - /// - /// let features = Attribute::from(("features".as_bytes(), "Bells & whistles".as_bytes())); - /// assert_eq!(features.value, "Bells & whistles".as_bytes()); - /// ``` - fn from(val: (&'a [u8], &'a [u8])) -> Attribute<'a> { - Attribute { - key: QName(val.0), - value: Cow::from(val.1), - } - } -} - impl<'a> From<(&'a str, &'a str)> for Attribute<'a> { /// Creates new attribute from text representation. /// Key is stored as-is, but the value will be escaped. diff --git a/src/se/var.rs b/src/se/var.rs index 46039dea..904b8888 100644 --- a/src/se/var.rs +++ b/src/se/var.rs @@ -139,7 +139,7 @@ where self.children.append(&mut self.buffer); } else { self.attrs - .push_attribute((key.as_bytes(), self.buffer.as_ref())); + .push_attribute(Attribute::new(key.as_bytes(), self.buffer.as_ref())); self.buffer.clear(); } }