-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
str::from_bytes #2268
Comments
The vector argument to For converting from C strings usually |
I actually have a [u8] buffer so from_c_str won't work without a cast. unsafe::from_bytes did stop at null characters though the docs don't specify how it is supposed to behave. |
The docs for |
Not sure why I thought str::unsafe::from_bytes stopped at nulls; it's working as you described. I'm don't know why str::from_bytes adds null bytes to the string though. It says that it converts "bytes to a UTF-8 string" and nulls are not valid utf-8. Which gets back to my original point: why is the safe interface even providing methods for operating on byte arrays? It's not like you can safely do anything with an arbitrary byte sequence so why not be more explicit and more useful and have from_utf8 instead? |
|
There is also the confusing @graydon, not sure which way you mean it should or shouldn't do, but a test case:
Prints 5 "A"s. I propose we (a) remove |
Still relevant. @erickt still going to do the rename? |
@jesse99: the string module doesn't need any special handling of |
Replaced with #8985, there's nothing else to do beyond renaming. |
In rust-lang#2268 I idly mused that the other user-overloadable operations could be added to this lint. Knowing that the lint was arguably incomplete was gnawing at the back of my mind, so I figured that I might as well make this PR, particularly given the change needed was so small.
Add the other overloadable operations to suspicious_arithmetic_impl In rust-lang#2268 I idly mused that the other user-overloadable operations could be added to this lint. Knowing that the lint was arguably incomplete was gnawing at the back of my mind, so I figured that I might as well make this PR, particularly given the change needed was so small. changelog: Start warning on suspicious implementations of the `BitAnd`, `BitOr`, `BitXor`, `Rem`, `Shl`, and `Shr` traits.
test that &mut !Unpin references are protected
The semantics of this should be tightened up (or probably even better new function(s) with better names should be added). Is the buffer supposed to be utf-8? 7-bit ASCII?
Also it should probably stop if it hits a NUL character. One place where this is annoying is inet_ntop which writes an ASCII representation of an address to a user provided buffer. With the way from_str works now you have to write silly code like:
The text was updated successfully, but these errors were encountered: