-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: c"…"
string literals
#3348
Conversation
6323fbc
to
9fdd8f1
Compare
Three weeks ago, the lang team said they would be interested in potentially doing this in the future. So here's an RFC. :) |
b19d91a
to
df9bd28
Compare
I'm on board. I'd even consider that a future extension might be to allow One other potential thing to thing about is whether |
|
||
Accepted escape codes: [Quote](https://doc.rust-lang.org/reference/tokens.html#quote-escapes) & [Unicode](https://doc.rust-lang.org/reference/tokens.html#unicode-escapes) & [Byte](https://doc.rust-lang.org/reference/tokens.html#byte-escapes). | ||
|
||
Unicode characters are accepted and encoded as UTF-8. That is, `c"🦀"`, `c"\u{1F980}"` and `c"\xf0\x9f\xa6\x80"` are all accepted and equivalent. |
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 wish byte string literals had this support too, so big 👍 on this!
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.
It might be worth proposing that in a separate RFC. That would also resolve one unresolved question of concat_bytes
, if we accept that mixing UTF-8 and non-UTF-8 in byte strings is okay.
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.
Wrote an RFC for that: #3349
I was hoping to make things like An alternative would be to allow literals like |
One concern I have is that if single-letter prefixes become common, extending the language with new prefixes can become confusing. Although, if |
Co-authored-by: konsumlamm <[email protected]>
I have two rhetorical questions with regards to the RFC text:
|
Do we even support
The exact same as would happen when using regular string literals. For example, |
|
||
- Also add `c'…'` C character literals? (`u8`, `i8`, `c_char`, or something more flexible?) | ||
|
||
- Should we make `&CStr` a thin pointer before stabilizing this? (If so, how?) |
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 think this should be a blocker on stabilization, yeah.
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 don't see how this feature is blocked by that at all really. It produces an &'static CStr
regardless of what &CStr
itself is made of.
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.
@Kixiron To be clear, I think considering that question should be a blocker for stabilization.
Given that a major use case of this will be FFI, it seems important that we have a simple, not-error-prone way of passing a C string to C functions. If we decide that &CStr
wasn't that mechanism, then we should decide what that mechanism should be, and make sure c"..."
works well with that.
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Just a minor additional note: I want to second that even if Just having (Polymorphic string literals is probably the ideal long-term position, but having However, as a data point, the |
Huzzah! The @rust-lang/lang team has decided to accept this RFC. To track further discussion, subscribe to the tracking issue here: |
…r-errors Implement RFC 3348, `c"foo"` literals RFC: rust-lang/rfcs#3348 Tracking issue: rust-lang#105723
…r-errors Implement RFC 3348, `c"foo"` literals RFC: rust-lang/rfcs#3348 Tracking issue: rust-lang#105723
…r-errors Implement RFC 3348, `c"foo"` literals RFC: rust-lang/rfcs#3348 Tracking issue: rust-lang#105723
Implement RFC 3348, `c"foo"` literals RFC: rust-lang/rfcs#3348 Tracking issue: #105723
Implement RFC 3348, `c"foo"` literals RFC: rust-lang/rfcs#3348 Tracking issue: #105723
Rendered