Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2120,12 +2120,12 @@ mod normalization {
fn utf8_0xc2() {
// All possible characters encoded in 2 bytes in UTF-8 which first byte is 0xC2 (0b11000010)
// Second byte follows the pattern 10xxxxxx
let first = str::from_utf8(&[0b11000010, 0b10000000])
let first = std::str::from_utf8(&[0b11000010, 0b10000000])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it would be better to import std::str::from_utf8 in the test module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what you mean - I don't think the changes I made are wrong, are they?

Or did you mean, instead of using the fully qualified path in multiple places, to add use std::str::from_utf8; and then refer to it as just from_utf8(...)? I've seen both usages across the code base, but AFAICT usage via the fully qualified path was much more frequent, so I went with that style for my PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I try to avoid using fully qualified paths, except there are only few places (1-3) to use and it is under cfg or inside of a macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Searching the source code with rg "std::str::from_utf8" shows me ~45 usages of the fully qualified path (not counting five use statements), and only ~10 usages of from_utf8 (where imported by use std::str::from_utf8). So clearly there are much more places where std::str::from_utf8 is referred to by the fully qualified path than there are places where the item imported and then referred to as just from_utf8.

So I'm not sure what you mean when you say "I try to avoid using fully qualified paths", as reality doesn't seem to confirm this :D

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, convinced

.unwrap()
.chars()
.next()
.unwrap();
let last = str::from_utf8(&[0b11000010, 0b10111111])
let last = std::str::from_utf8(&[0b11000010, 0b10111111])
.unwrap()
.chars()
.next()
Expand All @@ -2134,7 +2134,7 @@ mod normalization {
for ch in first..=last {
ch.encode_utf8(&mut utf8);
let description = format!("UTF-8 [{:02x} {:02x}] = `{}`", utf8[0], utf8[1], ch);
let input = str::from_utf8(&utf8).expect(&description);
let input = std::str::from_utf8(&utf8).expect(&description);

dbg!((input, &description));
if ch == '\u{0085}' {
Expand All @@ -2150,12 +2150,12 @@ mod normalization {
fn utf8_0x0d_0xc2() {
// All possible characters encoded in 2 bytes in UTF-8 which first byte is 0xC2 (0b11000010)
// Second byte follows the pattern 10xxxxxx
let first = str::from_utf8(&[0b11000010, 0b10000000])
let first = std::str::from_utf8(&[0b11000010, 0b10000000])
.unwrap()
.chars()
.next()
.unwrap();
let last = str::from_utf8(&[0b11000010, 0b10111111])
let last = std::str::from_utf8(&[0b11000010, 0b10111111])
.unwrap()
.chars()
.next()
Expand All @@ -2167,7 +2167,7 @@ mod normalization {
"UTF-8 [{:02x} {:02x} {:02x}] = `{}`",
utf8[0], utf8[1], utf8[2], ch
);
let input = str::from_utf8(&utf8).expect(&description);
let input = std::str::from_utf8(&utf8).expect(&description);

dbg!((input, &description));
if ch == '\u{0085}' {
Expand All @@ -2183,12 +2183,12 @@ mod normalization {
fn utf8_0xe2() {
// All possible characters encoded in 3 bytes in UTF-8 which first byte is 0xE2 (0b11100010)
// Second and third bytes follows the pattern 10xxxxxx
let first = str::from_utf8(&[0b11100010, 0b10000000, 0b10000000])
let first = std::str::from_utf8(&[0b11100010, 0b10000000, 0b10000000])
.unwrap()
.chars()
.next()
.unwrap();
let last = str::from_utf8(&[0b11100010, 0b10111111, 0b10111111])
let last = std::str::from_utf8(&[0b11100010, 0b10111111, 0b10111111])
.unwrap()
.chars()
.next()
Expand Down
3 changes: 1 addition & 2 deletions src/se/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ where
/// # use serde::Serialize;
/// # use pretty_assertions::assert_eq;
/// # use std::io::BufWriter;
/// # use std::str;
/// #[derive(Serialize)]
/// struct Root<'a> {
/// #[serde(rename = "@attribute")]
Expand All @@ -167,7 +166,7 @@ where
/// to_utf8_io_writer(&mut BufWriter::new(&mut buffer), &data).unwrap();
///
/// assert_eq!(
/// str::from_utf8(&buffer).unwrap(),
/// std::str::from_utf8(&buffer).unwrap(),
/// // The root tag name is automatically deduced from the struct name
/// // This will not work for other types or struct with #[serde(flatten)] fields
/// "<Root attribute=\"attribute content\">\
Expand Down
Loading