Conversation
|
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
|
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
This comment has been minimized.
This comment has been minimized.
|
Should |
|
@pitaj Eventually that seems perfectly reasonable. But that needs an error type, so I left them out of the first PR. (We can always add more later, especially while it's unstable.) |
library/core/src/ascii/ascii_char.rs
Outdated
There was a problem hiding this comment.
This unsafe block can be avoided by doing char::from(self.as_u8()).
There was a problem hiding this comment.
Good point! I should think more about my copy-pastes ;)
Updated.
There was a problem hiding this comment.
Oh, wait, const. No char::from in a const fn. Changed this to a FIXME instead.
There was a problem hiding this comment.
as casting works however:
| unsafe { char::from_u32_unchecked(self as u32) } | |
| self.as_u8() as char |
There was a problem hiding this comment.
Ah, right, yet another problem with as: I forget it works and it's not something with a signature in rustdoc to remind me 😬
library/core/src/char/methods.rs
Outdated
There was a problem hiding this comment.
Why does this take &self and not self?
There was a problem hiding this comment.
I agree that self would make more sense, but I think that for the existing is_ascii above too.
So I made this &self for consistency with the existing methods here. I'll add a note to the tracking issue to make sure that it's discussed further before stabilization.
library/core/src/num/mod.rs
Outdated
This comment has been minimized.
This comment has been minimized.
library/core/src/ascii/ascii_char.rs
Outdated
There was a problem hiding this comment.
| /// often known as the [ASCII]subset. | |
| /// often known as the [ASCII] subset. |
library/core/src/ascii/ascii_char.rs
Outdated
There was a problem hiding this comment.
as casting works however:
| unsafe { char::from_u32_unchecked(self as u32) } | |
| self.as_u8() as char |
library/core/src/ascii/ascii_char.rs
Outdated
There was a problem hiding this comment.
Bikeshedding incoming: Why not call the methods from_byte/as_byte? There is no stable precedent in the standard library for including the numeric type name in methods and from_byte is IMHO much simpler to read.
There was a problem hiding this comment.
There is, actually: https://doc.rust-lang.org/std/primitive.char.html#method.from_u32
So since it's char::from_u32, I figured that ascii::Char::from_u8 was the most consistent here.
But drop a note in the tracking issue if you feel strongly. I think that's a better place for bikeshedding discussions, so they'll be seen at (eventual) stabilization time.
There was a problem hiding this comment.
I totally missed that one! Seems very reasonable to rhyme with it. Bikeshedding complete 😉.
library/core/src/ascii/ascii_char.rs
Outdated
There was a problem hiding this comment.
Yeah I'm conflicted on this personally too. I agree with the decision at least in terms of this module internally, but I would personally very much like to just use use std::ascii; and ascii::Char instead of having to write out use std::ascii::AsciiChar;. It's an interesting stylistic point.
library/core/src/ascii/ascii_char.rs
Outdated
There was a problem hiding this comment.
I'm fine with landing it like this, but I find that an enum like this is super weird. I'll post more of a comment on the tracking issue because I don't think I fully understand the trade offs here yet.
library/core/src/ascii/ascii_char.rs
Outdated
There was a problem hiding this comment.
You don't have to do it now, but I would like to see a "Why would I use this?" section before stabilization. :-)
| #[inline] | ||
| pub const unsafe fn as_ascii_unchecked(&self) -> &[ascii::Char; N] { | ||
| let byte_ptr: *const [u8; N] = self; | ||
| let ascii_ptr = byte_ptr as *const [ascii::Char; N]; |
There was a problem hiding this comment.
Here we can use cast(), right? We can also use the newly added ptr::from_ref().
|
I think this is ready for review for nightly now: There's lots more to do here before it'd be ready for stabilization, but this is already 700+ lines, so I'd like to move those things (like putting examples on everything) into later PRs. |
|
Ship it. @bors r+ |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#108865 (Add a `sysroot` crate to represent the standard library crates) - rust-lang#110651 (libtest: include test output in junit xml reports) - rust-lang#110826 (Make PlaceMention a non-mutating use.) - rust-lang#110982 (Do not recurse into const generic args when resolving self lifetime elision.) - rust-lang#111009 (Add `ascii::Char` (ACP#179)) - rust-lang#111100 (check array type of repeat exprs is wf) - rust-lang#111186 (Add `is_positive` method for signed non-zero integers.) - rust-lang#111201 (bootstrap: add .gitmodules to the sources) Failed merges: - rust-lang#110954 (Reject borrows of projections in ConstProp.) r? `@ghost` `@rustbot` modify labels: rollup
ACP second: rust-lang/libs-team#179 (comment)
New tracking issue: #110998
For now this is an
enumas @kupiakos suggested, with the variants under a different feature flag.There's lots more things that could be added here, and place for further doc updates, but this seems like a plausible starting point PR.
I've gone through and put an
as_asciinext to everyis_ascii: onu8,char,[u8], andstr.As a demonstration, made a commit updating some formatting code to use this: scottmcm@ascii-char-in-fmt (I don't want to include that in this PR, though, because that brings in perf questions that don't exist if this is just adding new unstable APIs.)