Skip to content

Commit 3566ac9

Browse files
committed
Make attribute creation more uniform
closes #410
1 parent 0febc2b commit 3566ac9

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
Use methods on `Attribute` instead
9696

9797
- [#403]: Remove deprecated `quick_xml::de::from_bytes` and `Deserializer::from_borrowing_reader`
98+
- [#413]: Removed the `Attribute::from((&[u8], &[u8]))` implementation, use
99+
`Attribute::new(&[u8], &[u8])` instead.
98100

99101
### New Tests
100102

@@ -117,6 +119,7 @@
117119
[#395]: https://github.com/tafia/quick-xml/pull/395
118120
[#403]: https://github.com/tafia/quick-xml/pull/403
119121
[#407]: https://github.com/tafia/quick-xml/pull/407
122+
[#413]: https://github.com/tafia/quick-xml/pull/413
120123

121124
## 0.23.0 -- 2022-05-08
122125

src/events/attributes.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ pub struct Attribute<'a> {
3232
}
3333

3434
impl<'a> Attribute<'a> {
35+
36+
/// Creates new attribute from raw bytes.
37+
/// Does not apply any transformation to either key or value.
38+
///
39+
/// # Examples
40+
///
41+
/// ```
42+
/// # use pretty_assertions::assert_eq;
43+
/// use quick_xml::events::attributes::Attribute;
44+
///
45+
/// let features = Attribute::new("features".as_bytes(), "Bells &amp; whistles".as_bytes());
46+
/// assert_eq!(features.value, "Bells &amp; whistles".as_bytes());
47+
/// ```
48+
pub fn new(name: &'a [u8], val: &'a [u8]) -> Attribute<'a> {
49+
Attribute {
50+
key: QName(name),
51+
value: Cow::from(val),
52+
}
53+
}
54+
3555
/// Returns the unescaped value.
3656
///
3757
/// This is normally the value you are interested in. Escape sequences such as `&gt;` are
@@ -130,27 +150,6 @@ impl<'a> Debug for Attribute<'a> {
130150
}
131151
}
132152

133-
impl<'a> From<(&'a [u8], &'a [u8])> for Attribute<'a> {
134-
/// Creates new attribute from raw bytes.
135-
/// Does not apply any transformation to both key and value.
136-
///
137-
/// # Examples
138-
///
139-
/// ```
140-
/// # use pretty_assertions::assert_eq;
141-
/// use quick_xml::events::attributes::Attribute;
142-
///
143-
/// let features = Attribute::from(("features".as_bytes(), "Bells &amp; whistles".as_bytes()));
144-
/// assert_eq!(features.value, "Bells &amp; whistles".as_bytes());
145-
/// ```
146-
fn from(val: (&'a [u8], &'a [u8])) -> Attribute<'a> {
147-
Attribute {
148-
key: QName(val.0),
149-
value: Cow::from(val.1),
150-
}
151-
}
152-
}
153-
154153
impl<'a> From<(&'a str, &'a str)> for Attribute<'a> {
155154
/// Creates new attribute from text representation.
156155
/// Key is stored as-is, but the value will be escaped.

0 commit comments

Comments
 (0)