Skip to content

Commit 1d50907

Browse files
committed
Replace BytesStart::owned_name and BytesStart::borrowed_name by BytesStart::new
Replace `BytesStart::owned` and `BytesStart::borrowed` by `BytesStart::from_content`
1 parent 2595102 commit 1d50907

File tree

11 files changed

+100
-127
lines changed

11 files changed

+100
-127
lines changed

Changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@
150150
- [#431]: Changed event constructors:
151151
|Old names |New name
152152
|--------------------------------------------------|----------------------------------------------
153+
|`BytesStart::owned_name(impl Into<Vec<u8>>)` |`BytesStart::new(impl Into<Cow<str>>)`
154+
|`BytesStart::borrowed_name(&[u8])` |_(as above)_
155+
|`BytesStart::owned(impl Into<Vec<u8>>, usize)` |`BytesStart::from_content(impl Into<Cow<str>>, usize)`
156+
|`BytesStart::borrowed(&[u8], usize)` |_(as above)_
153157
|`BytesCData::new(impl Into<Cow<[u8]>>)` |`BytesCData::new(impl Into<Cow<str>>)`
154158
|`BytesCData::from_str(&str)` |_(as above)_
155159

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ loop {
8080

8181
// crates a new element ... alternatively we could reuse `e` by calling
8282
// `e.into_owned()`
83-
let mut elem = BytesStart::owned_name("my_elem");
83+
let mut elem = BytesStart::new("my_elem");
8484

8585
// collect existing attributes
8686
elem.extend_attributes(e.attributes().map(|attr| attr.unwrap()));

src/de/mod.rs

+29-47
Original file line numberDiff line numberDiff line change
@@ -1041,21 +1041,18 @@ mod tests {
10411041
assert_eq!(de.read, vec![]);
10421042
assert_eq!(de.write, vec![]);
10431043

1044-
assert_eq!(de.next().unwrap(), Start(BytesStart::borrowed_name("root")));
1045-
assert_eq!(
1046-
de.peek().unwrap(),
1047-
&Start(BytesStart::borrowed_name("inner"))
1048-
);
1044+
assert_eq!(de.next().unwrap(), Start(BytesStart::new("root")));
1045+
assert_eq!(de.peek().unwrap(), &Start(BytesStart::new("inner")));
10491046

10501047
// Should skip first <inner> tree
10511048
de.skip().unwrap();
10521049
assert_eq!(de.read, vec![]);
10531050
assert_eq!(
10541051
de.write,
10551052
vec![
1056-
Start(BytesStart::borrowed_name("inner")),
1053+
Start(BytesStart::new("inner")),
10571054
Text(BytesText::from_escaped_str("text")),
1058-
Start(BytesStart::borrowed_name("inner")),
1055+
Start(BytesStart::new("inner")),
10591056
End(BytesEnd::borrowed("inner")),
10601057
End(BytesEnd::borrowed("inner")),
10611058
]
@@ -1069,7 +1066,7 @@ mod tests {
10691066
// </inner>
10701067
// <target/>
10711068
// </root>
1072-
assert_eq!(de.next().unwrap(), Start(BytesStart::borrowed_name("next")));
1069+
assert_eq!(de.next().unwrap(), Start(BytesStart::new("next")));
10731070
assert_eq!(de.next().unwrap(), End(BytesEnd::borrowed("next")));
10741071

10751072
// We finish writing. Next call to `next()` should start replay that messages:
@@ -1087,25 +1084,22 @@ mod tests {
10871084
assert_eq!(
10881085
de.read,
10891086
vec![
1090-
Start(BytesStart::borrowed_name("inner")),
1087+
Start(BytesStart::new("inner")),
10911088
Text(BytesText::from_escaped_str("text")),
1092-
Start(BytesStart::borrowed_name("inner")),
1089+
Start(BytesStart::new("inner")),
10931090
End(BytesEnd::borrowed("inner")),
10941091
End(BytesEnd::borrowed("inner")),
10951092
]
10961093
);
10971094
assert_eq!(de.write, vec![]);
1098-
assert_eq!(
1099-
de.next().unwrap(),
1100-
Start(BytesStart::borrowed_name("inner"))
1101-
);
1095+
assert_eq!(de.next().unwrap(), Start(BytesStart::new("inner")));
11021096

11031097
// Skip `#text` node and consume <inner/> after it
11041098
de.skip().unwrap();
11051099
assert_eq!(
11061100
de.read,
11071101
vec![
1108-
Start(BytesStart::borrowed_name("inner")),
1102+
Start(BytesStart::new("inner")),
11091103
End(BytesEnd::borrowed("inner")),
11101104
End(BytesEnd::borrowed("inner")),
11111105
]
@@ -1119,10 +1113,7 @@ mod tests {
11191113
]
11201114
);
11211115

1122-
assert_eq!(
1123-
de.next().unwrap(),
1124-
Start(BytesStart::borrowed_name("inner"))
1125-
);
1116+
assert_eq!(de.next().unwrap(), Start(BytesStart::new("inner")));
11261117
assert_eq!(de.next().unwrap(), End(BytesEnd::borrowed("inner")));
11271118

11281119
// We finish writing. Next call to `next()` should start replay messages:
@@ -1148,10 +1139,7 @@ mod tests {
11481139
Text(BytesText::from_escaped_str("text"))
11491140
);
11501141
assert_eq!(de.next().unwrap(), End(BytesEnd::borrowed("inner")));
1151-
assert_eq!(
1152-
de.next().unwrap(),
1153-
Start(BytesStart::borrowed_name("target"))
1154-
);
1142+
assert_eq!(de.next().unwrap(), Start(BytesStart::new("target")));
11551143
assert_eq!(de.next().unwrap(), End(BytesEnd::borrowed("target")));
11561144
assert_eq!(de.next().unwrap(), End(BytesEnd::borrowed("root")));
11571145
}
@@ -1177,17 +1165,17 @@ mod tests {
11771165
assert_eq!(de.read, vec![]);
11781166
assert_eq!(de.write, vec![]);
11791167

1180-
assert_eq!(de.next().unwrap(), Start(BytesStart::borrowed_name("root")));
1168+
assert_eq!(de.next().unwrap(), Start(BytesStart::new("root")));
11811169

11821170
// Skip the <skip> tree
11831171
de.skip().unwrap();
11841172
assert_eq!(de.read, vec![]);
11851173
assert_eq!(
11861174
de.write,
11871175
vec![
1188-
Start(BytesStart::borrowed_name("skip")),
1176+
Start(BytesStart::new("skip")),
11891177
Text(BytesText::from_escaped_str("text")),
1190-
Start(BytesStart::borrowed_name("skip")),
1178+
Start(BytesStart::new("skip")),
11911179
End(BytesEnd::borrowed("skip")),
11921180
End(BytesEnd::borrowed("skip")),
11931181
]
@@ -1200,18 +1188,15 @@ mod tests {
12001188
// <skip/>
12011189
// </skip>
12021190
// </root>
1203-
assert_eq!(
1204-
de.next().unwrap(),
1205-
Start(BytesStart::borrowed_name("target"))
1206-
);
1191+
assert_eq!(de.next().unwrap(), Start(BytesStart::new("target")));
12071192
de.read_to_end(QName(b"target")).unwrap();
12081193
assert_eq!(de.read, vec![]);
12091194
assert_eq!(
12101195
de.write,
12111196
vec![
1212-
Start(BytesStart::borrowed_name("skip")),
1197+
Start(BytesStart::new("skip")),
12131198
Text(BytesText::from_escaped_str("text")),
1214-
Start(BytesStart::borrowed_name("skip")),
1199+
Start(BytesStart::new("skip")),
12151200
End(BytesEnd::borrowed("skip")),
12161201
End(BytesEnd::borrowed("skip")),
12171202
]
@@ -1231,16 +1216,16 @@ mod tests {
12311216
assert_eq!(
12321217
de.read,
12331218
vec![
1234-
Start(BytesStart::borrowed_name("skip")),
1219+
Start(BytesStart::new("skip")),
12351220
Text(BytesText::from_escaped_str("text")),
1236-
Start(BytesStart::borrowed_name("skip")),
1221+
Start(BytesStart::new("skip")),
12371222
End(BytesEnd::borrowed("skip")),
12381223
End(BytesEnd::borrowed("skip")),
12391224
]
12401225
);
12411226
assert_eq!(de.write, vec![]);
12421227

1243-
assert_eq!(de.next().unwrap(), Start(BytesStart::borrowed_name("skip")));
1228+
assert_eq!(de.next().unwrap(), Start(BytesStart::new("skip")));
12441229
de.read_to_end(QName(b"skip")).unwrap();
12451230

12461231
assert_eq!(de.next().unwrap(), End(BytesEnd::borrowed("root")));
@@ -1293,25 +1278,22 @@ mod tests {
12931278
"#,
12941279
);
12951280

1296-
assert_eq!(de.next().unwrap(), Start(BytesStart::borrowed_name("root")));
1281+
assert_eq!(de.next().unwrap(), Start(BytesStart::new("root")));
12971282

12981283
assert_eq!(
12991284
de.next().unwrap(),
1300-
Start(BytesStart::borrowed(r#"tag a="1""#, 3))
1285+
Start(BytesStart::from_content(r#"tag a="1""#, 3))
13011286
);
13021287
assert_eq!(de.read_to_end(QName(b"tag")).unwrap(), ());
13031288

13041289
assert_eq!(
13051290
de.next().unwrap(),
1306-
Start(BytesStart::borrowed(r#"tag a="2""#, 3))
1291+
Start(BytesStart::from_content(r#"tag a="2""#, 3))
13071292
);
13081293
assert_eq!(de.next().unwrap(), CData(BytesCData::new("cdata content")));
13091294
assert_eq!(de.next().unwrap(), End(BytesEnd::borrowed("tag")));
13101295

1311-
assert_eq!(
1312-
de.next().unwrap(),
1313-
Start(BytesStart::borrowed_name("self-closed"))
1314-
);
1296+
assert_eq!(de.next().unwrap(), Start(BytesStart::new("self-closed")));
13151297
assert_eq!(de.read_to_end(QName(b"self-closed")).unwrap(), ());
13161298

13171299
assert_eq!(de.next().unwrap(), End(BytesEnd::borrowed("root")));
@@ -1382,17 +1364,17 @@ mod tests {
13821364
assert_eq!(
13831365
events,
13841366
vec![
1385-
Start(BytesStart::borrowed(
1367+
Start(BytesStart::from_content(
13861368
r#"item name="hello" source="world.rs""#,
13871369
4
13881370
)),
13891371
Text(BytesText::from_escaped_str("Some text")),
13901372
End(BytesEnd::borrowed("item")),
1391-
Start(BytesStart::borrowed("item2", 5)),
1373+
Start(BytesStart::from_content("item2", 5)),
13921374
End(BytesEnd::borrowed("item2")),
1393-
Start(BytesStart::borrowed("item3", 5)),
1375+
Start(BytesStart::from_content("item3", 5)),
13941376
End(BytesEnd::borrowed("item3")),
1395-
Start(BytesStart::borrowed(r#"item4 value="world" "#, 5)),
1377+
Start(BytesStart::from_content(r#"item4 value="world" "#, 5)),
13961378
End(BytesEnd::borrowed("item4")),
13971379
]
13981380
)
@@ -1413,7 +1395,7 @@ mod tests {
14131395

14141396
assert_eq!(
14151397
reader.next().unwrap(),
1416-
DeEvent::Start(BytesStart::borrowed("item ", 4))
1398+
DeEvent::Start(BytesStart::from_content("item ", 4))
14171399
);
14181400
reader.read_to_end(QName(b"item")).unwrap();
14191401
assert_eq!(reader.next().unwrap(), DeEvent::Eof);

src/de/seq.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ where
134134

135135
#[test]
136136
fn test_not_in() {
137-
let tag = BytesStart::borrowed_name("tag");
137+
let tag = BytesStart::new("tag");
138138

139139
assert_eq!(not_in(&[], &tag, Decoder::utf8()).unwrap(), true);
140140
assert_eq!(

0 commit comments

Comments
 (0)