Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: a byte string concatenation macro #566
Conversation
mzabaluev
added some commits
Jan 10, 2015
This comment has been minimized.
This comment has been minimized.
netvl
commented
Jan 11, 2015
|
Big +1. I used this macro in my networking programs extensively and I never saw the reason to remove it. It does a different thing than byte literals do. Byte literals are good when you have ASCII data; when you want to work with numbers instead of characters, it becomes very unwieldy. |
This comment has been minimized.
This comment has been minimized.
If you have only numbers, you can use the array syntax: |
This comment has been minimized.
This comment has been minimized.
netvl
commented
Jan 11, 2015
|
@SimonSapin, I should have expressed myself better. Of course, I meant the situation when numbers are mixed with characters. |
This comment has been minimized.
This comment has been minimized.
|
It seems somewhat inconsistent to me for string concatenation to be called |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Yeah, there is a note about possibly naming it |
brson
self-assigned this
Jan 22, 2015
This comment has been minimized.
This comment has been minimized.
|
What are the workarounds for the lack of this functionality? |
This comment has been minimized.
This comment has been minimized.
None that I know to work in macros. |
This comment has been minimized.
This comment has been minimized.
|
@brson This seems like a fair description. So I’d be fine with:
|
This comment has been minimized.
This comment has been minimized.
kjpgit
commented
Jan 30, 2015
|
I would like a way to have a long (>100) byte string literal but keep everything under 80 columns and make it multi line in source code. I think this does that, so +1 |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin As a bonus, that'll be consistent with |
This comment has been minimized.
This comment has been minimized.
|
ping @brson |
This comment has been minimized.
This comment has been minimized.
|
I'm afraid that at this time we just don't want to do this. It's niche functionality, and it can be done in a plugin. Let's table this and see if it comes back to bite us again. Thanks, and sorry for dragging this out. |
brson
closed this
Apr 9, 2015
This comment has been minimized.
This comment has been minimized.
Like in Unicode string, a newline can be escaped with assert_eq!(b"foo", b"fo\
o"); |
This comment has been minimized.
This comment has been minimized.
|
I do not understand why this was removed. It can be done in a plugin, sure, but Rust 1.0 doesn't support plugins. And it's not niche functionality when you're trying to avoid copies for binary protocols, as is often the case in networking. |
This comment has been minimized.
This comment has been minimized.
casey
commented
Jul 29, 2017
|
May I propose that this be re-opend? I needed this today, and was surprised that it doesn't exist. It seems that if |
This comment has been minimized.
This comment has been minimized.
|
There is no way to do a macro for NUL-terminated byte sequences without a Procedural macros for arbitrary expressions are far from being stable, right? |
nox
unassigned
brson
Nov 22, 2017
This comment has been minimized.
This comment has been minimized.
Ferdi265
commented
Jan 15, 2019
|
Stumbled upon this today. Compile-time concatenating byte literals or byte arrays should really be a thing |
This comment has been minimized.
This comment has been minimized.
danielhenrymantilla
commented
Feb 16, 2019
|
I have come up with a solution that works in stable rust: https://docs.rs/byte-strings/0.1.0/byte_strings/macro.c_str.html |
mzabaluev commentedJan 10, 2015
The removed
bytes!macro is still needed and should be brought back, updated to accept byte string literals.Rendered