-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Book section on FFI with nullable pointers doesn't explain None == null. #34250
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
I'm not really working on the old book anymore, but would love to take a patch for this if someone would like to write one. |
@steveklabnik: could you point me to the new book? |
http://rust-lang.github.io/book On Jun 13, 2016, 10:50 +0200, Sander Maijersnotifications@github.com, wrote:
|
@eddyb it does say
Do you just think it should more explicitly spell out that |
@durka Yes, I think the description might not be clear without the definition of |
@eddyb agreed, I'll mention that too. And IMO it's unfortunate to call this On Mon, Jun 13, 2016 at 12:54 PM, Eduard-Mihai Burtescu <
|
see #34258 On Mon, Jun 13, 2016 at 1:03 PM, Alex Burka durka42@gmail.com wrote:
|
book/ffi: nullable pointer cleanup Expand the "nullable pointer optimization" section with a code example. Fixes rust-lang#34250. I also noticed that many of the examples use the libc crate just for types such as `c_char` and `c_int`, which are now available through `std::os::raw`. I changed the ones that don't need to rely on libc. I'm glad to revert that part of the commit if it's unwanted churn.
The paragraph in question (https://doc.rust-lang.org/book/ffi.html#the-nullable-pointer-optimization):
While the paragraph does a good job at explaining when this optimizations happens (although it's missing the fact that the optimization can now look for deeply nested fields to use), it doesn't explicitly mention that
None
represents the "NULL" value and thatSome(function)
is how you create non-"NULL" values, nor does it have a code example.What this can lead to is code that transmutes because it might not be entirely clear that there's a safe way to create values of that type.
cc @steveklabnik
The text was updated successfully, but these errors were encountered: