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