-
Notifications
You must be signed in to change notification settings - Fork 13.4k
CStr should have a function like from_bytes_with_nul() that reads until the first '\0' #49107
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This has been proposed before as #20475, and closed because this is already supported by the package |
That's a bit sad and problematic that such a basic functionality isn't implemented on |
Why does |
@kanekv are you talking about in C? Because in C |
@kennytm is there a possibility to accept such function inside |
@patrickelectric I agree. The reason that some functionality is offered by a thirdparty crate is not a valid reason to not have it in std. |
|
When dealing with FFI (fixed char buffers in file formats that represent strings and passing fixed char buffers to C code to write chars to them up to a given max len) I often find myself doing this:
Because if I pass the whole slice to it, it returns a
FromBytesWithNulError
.There should be a function that combines both lines and read until the first
'\0'
byte in the slice.Something like:
And yes, I did write my own function for my use case but I find myself copying these two lines around into different projects dealing with FFI and I think it would make sense to have this (arguably) "basic functionality" in std's
CStr
:)The text was updated successfully, but these errors were encountered: