Skip to content

Commit 0b38ea1

Browse files
committed
Convert namespace-related structs to str
1 parent 8a14c1a commit 0b38ea1

File tree

17 files changed

+363
-373
lines changed

17 files changed

+363
-373
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/nested_readers.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -46,7 +45,7 @@ pub enum Error {
4645
/// Escape error
4746
EscapeError(EscapeError),
4847
/// Specified namespace prefix is unknown, cannot resolve namespace for it
49-
UnknownPrefix(Vec<u8>),
48+
UnknownPrefix(String),
5049
}
5150

5251
impl From<IoError> for Error {
@@ -116,11 +115,7 @@ impl fmt::Display for Error {
116115
Error::EmptyDocType => write!(f, "DOCTYPE declaration must not be empty"),
117116
Error::InvalidAttr(e) => write!(f, "error while parsing attribute: {}", e),
118117
Error::EscapeError(e) => write!(f, "{}", e),
119-
Error::UnknownPrefix(prefix) => {
120-
f.write_str("Unknown namespace prefix '")?;
121-
write_byte_string(f, prefix)?;
122-
f.write_str("'")
123-
}
118+
Error::UnknownPrefix(prefix) => write!(f, "Unknown namespace prefix '{}'", prefix),
124119
}
125120
}
126121
}
@@ -170,15 +165,15 @@ pub mod serialize {
170165
/// Deserializer encounter a start tag with a specified name when it is
171166
/// not expecting. This happens when you try to deserialize a primitive
172167
/// value (numbers, strings, booleans) from an XML element.
173-
UnexpectedStart(Vec<u8>),
168+
UnexpectedStart(String),
174169
/// Deserializer encounter an end tag with a specified name when it is
175170
/// not expecting. Usually that should not be possible, because XML reader
176171
/// is not able to produce such stream of events that lead to this error.
177172
///
178173
/// If you get this error this likely indicates and error in the `quick_xml`.
179174
/// Please open an issue at <https://github.com/tafia/quick-xml>, provide
180175
/// your Rust code and XML input.
181-
UnexpectedEnd(Vec<u8>),
176+
UnexpectedEnd(String),
182177
/// The [`Reader`] produced [`Event::Eof`] when it is not expecting,
183178
/// for example, after producing [`Event::Start`] but before corresponding
184179
/// [`Event::End`].
@@ -224,12 +219,12 @@ pub mod serialize {
224219
DeError::KeyNotRead => write!(f, "Invalid `Deserialize` implementation: `MapAccess::next_value[_seed]` was called before `MapAccess::next_key[_seed]`"),
225220
DeError::UnexpectedStart(e) => {
226221
f.write_str("Unexpected `Event::Start(")?;
227-
write_byte_string(f, e)?;
222+
write_byte_string(f, e.as_bytes())?;
228223
f.write_str(")`")
229224
}
230225
DeError::UnexpectedEnd(e) => {
231226
f.write_str("Unexpected `Event::End(")?;
232-
write_byte_string(f, e)?;
227+
write_byte_string(f, e.as_bytes())?;
233228
f.write_str(")`")
234229
}
235230
DeError::UnexpectedEof => write!(f, "Unexpected `Event::Eof`"),

0 commit comments

Comments
 (0)