Skip to content

Commit b816b2d

Browse files
committed
Convert namespace-related structs to str
1 parent 589585e commit b816b2d

File tree

18 files changed

+365
-375
lines changed

18 files changed

+365
-375
lines changed

benches/microbenches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn attributes(c: &mut Criterion) {
224224
let mut count = criterion::black_box(0);
225225
loop {
226226
match r.read_event() {
227-
Ok(Event::Empty(e)) if e.name() == QName(b"player") => {
227+
Ok(Event::Empty(e)) if e.name() == QName("player") => {
228228
for name in ["num", "status", "avg"] {
229229
if let Some(_attr) = e.try_get_attribute(name).unwrap() {
230230
count += 1

examples/custom_entities.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4141
}
4242
}
4343
Ok(Event::Start(ref e)) => match e.name().as_ref() {
44-
b"test" => {
44+
"test" => {
4545
let attributes = e
4646
.attributes()
4747
.map(|a| {

examples/nested_readers.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() -> Result<(), quick_xml::Error> {
2222
loop {
2323
match reader.read_event_into(&mut buf)? {
2424
Event::Start(element) => match element.name().as_ref() {
25-
b"w:tbl" => {
25+
"w:tbl" => {
2626
count += 1;
2727
let mut stats = TableStat {
2828
index: count,
@@ -35,20 +35,17 @@ fn main() -> Result<(), quick_xml::Error> {
3535
skip_buf.clear();
3636
match reader.read_event_into(&mut skip_buf)? {
3737
Event::Start(element) => match element.name().as_ref() {
38-
b"w:tr" => {
38+
"w:tr" => {
3939
stats.rows.push(vec![]);
4040
row_index = stats.rows.len() - 1;
4141
}
42-
b"w:tc" => {
43-
stats.rows[row_index].push(
44-
String::from_utf8(element.name().as_ref().to_vec())
45-
.unwrap(),
46-
);
42+
"w:tc" => {
43+
stats.rows[row_index].push(element.name().as_ref().to_owned());
4744
}
4845
_ => {}
4946
},
5047
Event::End(element) => {
51-
if element.name().as_ref() == b"w:tbl" {
48+
if element.name().as_ref() == "w:tbl" {
5249
found_tables.push(stats);
5350
break;
5451
}

examples/read_buffered.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ fn main() -> Result<(), quick_xml::Error> {
1717
loop {
1818
match reader.read_event_into(&mut buf) {
1919
Ok(Event::Start(ref e)) => {
20-
let name = e.name();
21-
let name = reader.decoder().decode(name.as_ref())?;
22-
println!("read start event {:?}", name.as_ref());
20+
println!("read start event {:?}", e.name().as_ref());
2321
count += 1;
2422
}
2523
Ok(Event::Eof) => break, // exits the loop when reaching end of file

examples/read_texts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010

1111
loop {
1212
match reader.read_event() {
13-
Ok(Event::Start(e)) if e.name().as_ref() == b"tag2" => {
13+
Ok(Event::Start(e)) if e.name().as_ref() == "tag2" => {
1414
// read_text_into for buffered readers not implemented
1515
let txt = reader
1616
.read_text(e.name())

src/errors.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::escape::EscapeError;
44
use crate::events::attributes::AttrError;
5-
use crate::utils::write_byte_string;
65
use std::fmt;
76
use std::io::Error as IoError;
87
use std::str::Utf8Error;
@@ -38,7 +37,7 @@ pub enum Error {
3837
/// Escape error
3938
EscapeError(EscapeError),
4039
/// Specified namespace prefix is unknown, cannot resolve namespace for it
41-
UnknownPrefix(Vec<u8>),
40+
UnknownPrefix(String),
4241
}
4342

4443
impl From<IoError> for Error {
@@ -107,11 +106,7 @@ impl fmt::Display for Error {
107106
),
108107
Error::InvalidAttr(e) => write!(f, "error while parsing attribute: {}", e),
109108
Error::EscapeError(e) => write!(f, "{}", e),
110-
Error::UnknownPrefix(prefix) => {
111-
f.write_str("Unknown namespace prefix '")?;
112-
write_byte_string(f, prefix)?;
113-
f.write_str("'")
114-
}
109+
Error::UnknownPrefix(prefix) => write!(f, "Unknown namespace prefix '{}'", prefix),
115110
}
116111
}
117112
}
@@ -161,15 +156,15 @@ pub mod serialize {
161156
/// Deserializer encounter a start tag with a specified name when it is
162157
/// not expecting. This happens when you try to deserialize a primitive
163158
/// value (numbers, strings, booleans) from an XML element.
164-
UnexpectedStart(Vec<u8>),
159+
UnexpectedStart(String),
165160
/// Deserializer encounter an end tag with a specified name when it is
166161
/// not expecting. Usually that should not be possible, because XML reader
167162
/// is not able to produce such stream of events that lead to this error.
168163
///
169164
/// If you get this error this likely indicates and error in the `quick_xml`.
170165
/// Please open an issue at <https://github.com/tafia/quick-xml>, provide
171166
/// your Rust code and XML input.
172-
UnexpectedEnd(Vec<u8>),
167+
UnexpectedEnd(String),
173168
/// The [`Reader`] produced [`Event::Eof`] when it is not expecting,
174169
/// for example, after producing [`Event::Start`] but before corresponding
175170
/// [`Event::End`].
@@ -215,12 +210,12 @@ pub mod serialize {
215210
DeError::KeyNotRead => write!(f, "Invalid `Deserialize` implementation: `MapAccess::next_value[_seed]` was called before `MapAccess::next_key[_seed]`"),
216211
DeError::UnexpectedStart(e) => {
217212
f.write_str("Unexpected `Event::Start(")?;
218-
write_byte_string(f, e)?;
213+
write_byte_string(f, e.as_bytes())?;
219214
f.write_str(")`")
220215
}
221216
DeError::UnexpectedEnd(e) => {
222217
f.write_str("Unexpected `Event::End(")?;
223-
write_byte_string(f, e)?;
218+
write_byte_string(f, e.as_bytes())?;
224219
f.write_str(")`")
225220
}
226221
DeError::UnexpectedEof => write!(f, "Unexpected `Event::Eof`"),

0 commit comments

Comments
 (0)