-
Notifications
You must be signed in to change notification settings - Fork 13.3k
consider including byte literals (alternative to integer literals for [u8] and u8) #4334
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
Comments
This could be implemented as a syntax extension, maybe? But it would have to be |
@catamorphism: that's a good idea, but do you think that could work for an |
I believe that allowing byte literals like this would make using some C APIs like Spidermonkey significantly easier, since things like JSClass instances could finally just be constant data. |
A syntax extension would be able to produce |
Nominating for well-covered |
accepted for feature complete |
@graydon, |
afaict he means |
Now we have |
|
Well, if |
There's also |
One consideration is that since #6417 |
Ok, good reason :) |
@sanxiyn I don't think macros parse as patterns yet:
|
Syntax extensions can inspect types, right? Could |
Syntax extensions can't inspect types properly, but they can tell whether a given literal is a |
Here are the basics of what I want. I've been needing to deal with bytes a lot in rust-http, and there will be many other similar projects that do have to deal with bytes a lot. Firstly: Secondly: Thirdly: sigil support for the two above which removes the implied |
I'm a fan of |
@kballard: the problem I have with that syntax is it not being clear what the corresponding (if any) string literals would be, like |
@thestinger String literals like that don't make sense. The only sensible string literal is the byte literal, and I don't think there's any need to use the same syntax for string-literal-as-[u8] vs char-literal-as-specified-integral-type, as they're distinct concepts. |
So |
@thestinger Yeah, that's what I'm thinking is the most sensible. |
Added back the RFC tag. It's not clear that |
As @huonw said earlier, I’d like something that is usable in patterns. This is currently invalid:
|
+1 to @chris-morgan’s proposal: #4334 (comment) |
P-low, not 1.0 blocker. |
This should be a new-style RFC. |
Thanks @SimonSapin (rust-lang/rfcs#69). |
It would be nice if
b"foo"
could be used instead ofstr::as_bytes_slice("foo")
, and especially~b"bar"
instead ofvec::from_slice(str::as_bytes_slice("bar"))
. Python uses this convention and only allows ASCII inside the byte string literals (along with byte escape codes). I don't really think it's necessary to forbid Unicode though - Python does that to make a very clear distinction between bytes and strings.There could also be a byte version of a
char
literal, allowing any ASCII character (b'\n'
) - a55u8
literal removes the need for escape codes there.The text was updated successfully, but these errors were encountered: