-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
std: Stabilize the ascii
module
#22024
Conversation
cc @SimonSapin r? @aturon |
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
Note that this does not currently mark the methods/trait as |
One downside of these changes is that |
When is this useful? |
Strictly speaking |
@huonw Ok, |
Hm that's a good point, I had not considered that. Having two traits isn't necessarily the end of the world, so perhaps this makes it worth it to have. Out of curiosity, do you think that having two vs one trait for this is ok?
I didn't originally have a use for it, but I've been doing it with other common traits (mainly just because it's possible), so I figured I'd throw it in. I'd be find leaving it until later though. |
As far as I can tell, there are two uses for a trait: have it in scope to call methods, and use it as a bound in generics. This impl doesn’t help the former: any method of So, although having this impl doesn’t hurt, I’d go with “you ain’t gonna need it”. It can always be added later if needed. |
Sorry for the long delay looking at this. I like moving to an associated type and iterator, but agree with @SimonSapin on the other points. |
ascii
module
I've updated this PR and because the changes are so minor now I've marked all contents as re-r? @SimonSapin and @aturon |
Looks good to me. |
So, I'm sorry to be suggesting this so late, but something about this design has always bugged me, and I think I just put my finger on it: the use of the To make this work, we'd need a Thoughts? Am I missing something? |
Hm, could you sketch that out a little more concretely? I think we could safely implement |
Sure, mutating methods instead of by-value I don’t think |
One slightly problem might be that if we have something like |
These methods would be on the |
They're not equivalent, because the
The idea was to not impl on String/Vec at all, but to work directly on slices. (See sketch below)
Right, so we don't use Here's what I have in mind. We have a single trait pub trait AsciiExt {
type Owned;
fn is_ascii(&self) -> bool;
fn to_ascii_uppercase(&self) -> Owned;
fn to_ascii_lowercase(&self) -> Owned;
fn make_ascii_uppercase(&mut self);
fn make_ascii_lowercase(&mut self);
fn eq_ignore_ascii_case(&self, other: &Self) -> bool;
} and this trait would be implemented for: For this to work, we need |
Note: the naming of the methods in the above sketch is a strawman, we badly need a convention here. |
Ooh, I see. Yes, that makes sense. And having a single trait is nicer. |
How would you guys feel about moving to that today? We could leave |
@alexcrichton I'd be fine with that, modulo that I'm not really fond of |
Previously an implementation of a stable trait allows implementations of unstable methods. This updates the stability pass to ensure that all items of an impl block of a trait are indeed stable on the trait itself.
This commit performs a stabilization pass over the `std::ascii` module taking the following actions: * the module name is now stable * `AsciiExt` is now stable after moving its type parameter to an `Owned` associated type * `AsciiExt::is_ascii` is now stable * `AsciiExt::to_ascii_uppercase` is now stable * `AsciiExt::to_ascii_lowercase` is now stable * `AsciiExt::eq_ignore_ascii_case` is now stable * `AsciiExt::make_ascii_uppercase` is added to possibly replace `OwnedAsciiExt::into_ascii_uppercase` (similarly for lowercase variants). * `escape_default` now returns an iterator and is stable * `EscapeDefault` is now stable Trait implementations are now also marked stable. Primarily it is still unstable to *implement* the `AsciiExt` trait due to it containing some unstable methods. [breaking-change]
Ok, updated with mentioned changes, r? @aturon |
* Move the type parameter on the `AsciiExt` trait to an associated type named `Owned`. * Move `ascii::escape_default` to using an iterator. This is a breaking change due to the removal of the type parameter on the `AsciiExt` trait as well as the modifications to the `escape_default` function to returning an iterator. Manual implementations of `AsciiExt` (or `AsciiExt` bounds) should be adjusted to remove the type parameter and using the new `escape_default` should be relatively straightforward. [breaking-change]
⌛ Testing commit 235f35b with merge 8a91f08... |
💔 Test failed - auto-mac-64-nopt-t |
Looks like http://www.reddit.com/r/rust/comments/2xr7i1/how_to_call_strmake_ascii_uppercasemut_self/ |
Also, should |
Yes that is currently intentional. Implementing |
AsciiExt
trait to an associated type namedOwned
.ascii::escape_default
to using an iterator.This is a breaking change due to the removal of the type parameter on the
AsciiExt
trait as well as the modifications to theescape_default
functionto returning an iterator. Manual implementations of
AsciiExt
(orAsciiExt
bounds) should be adjusted to remove the type parameter and using the new
escape_default
should be relatively straightforward.[breaking-change]