Skip to content

Commit 2b765ab

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

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
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: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ pub struct Attribute<'a> {
3232
}
3333

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

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-
154152
impl<'a> From<(&'a str, &'a str)> for Attribute<'a> {
155153
/// Creates new attribute from text representation.
156154
/// Key is stored as-is, but the value will be escaped.

src/se/var.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ where
139139
self.children.append(&mut self.buffer);
140140
} else {
141141
self.attrs
142-
.push_attribute((key.as_bytes(), self.buffer.as_ref()));
142+
.push_attribute(Attribute::new(key.as_bytes(), self.buffer.as_ref()));
143143
self.buffer.clear();
144144
}
145145
}

0 commit comments

Comments
 (0)