-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the width
function of char
return u32
#23539
Conversation
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
@@ -7603,13 +7603,13 @@ pub mod charwidth { | |||
} | |||
} | |||
|
|||
pub fn width(c: char, is_cjk: bool) -> Option<usize> { | |||
pub fn width(c: char, is_cjk: bool) -> Option<u32> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe these files should be changed by changing src/etc/unicode.py
, not by hand-editing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -77,7 +77,7 @@ impl UnicodeStr for str { | |||
fn is_alphanumeric(&self) -> bool { self.chars().all(|c| c.is_alphanumeric()) } | |||
|
|||
#[inline] | |||
fn width(&self, is_cjk: bool) -> usize { | |||
fn width(&self, is_cjk: bool) -> u32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this seems like somewhat of an edge case: the width of a string will typically be fairly similar (at least, proportional) to its size in memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh, maybe this is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe that calls for u64
, for integers that do not clearly fall in the range of u32
?
IMO, it's a mistake. |
@petrochenkov I believe that this is different from things like |
☔ The latest upstream changes (presumably #23796) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @aturon (transferring reviewership, don't have the bandwidth right now.) |
The width of a Unicode codepoint is not related to some in-memory buffer.
@aturon Rebased. |
@tbu- I feel like this is definitely an edge case, and probably ergonomic concerns (about the integer contexts in which you might be using this) apply. Can you think of any way to gather data on this? It's very difficult to make this decision in isolation. |
☔ The latest upstream changes (presumably #24428) made this pull request unmergeable. Please resolve the merge conflicts. |
This function is now deprecated in favor of an external crate, so I'm going to close this for now. Feel free to open a PR against that crate though! |
The width of a Unicode codepoint is not related to some in-memory buffer.