@@ -32,6 +32,25 @@ pub struct Attribute<'a> {
32
32
}
33
33
34
34
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 & whistles".as_bytes());
45
+ /// assert_eq!(features.value, "Bells & 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
+
35
54
/// Returns the unescaped value.
36
55
///
37
56
/// This is normally the value you are interested in. Escape sequences such as `>` are
@@ -130,27 +149,6 @@ impl<'a> Debug for Attribute<'a> {
130
149
}
131
150
}
132
151
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 & whistles".as_bytes()));
144
- /// assert_eq!(features.value, "Bells & 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
-
154
152
impl < ' a > From < ( & ' a str , & ' a str ) > for Attribute < ' a > {
155
153
/// Creates new attribute from text representation.
156
154
/// Key is stored as-is, but the value will be escaped.
0 commit comments