From e934f316104971d5eb6f1e2148eeec9afbd7dbbb Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Wed, 16 Oct 2024 11:07:09 -0600 Subject: [PATCH] Ch. 20: correct text about how we got raw pointers We no longer get the raw pointers from references, although we *could*, because we can now use the raw pointer operator rather than an `as` cast and thus can get them directly from a variable in scope. --- src/ch20-01-unsafe-rust.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ch20-01-unsafe-rust.md b/src/ch20-01-unsafe-rust.md index 2be392c7e..156c0f05f 100644 --- a/src/ch20-01-unsafe-rust.md +++ b/src/ch20-01-unsafe-rust.md @@ -88,10 +88,9 @@ By opting out of having Rust enforce these guarantees, you can give up guaranteed safety in exchange for greater performance or the ability to interface with another language or hardware where Rust’s guarantees don’t apply. -Listing 20-1 shows how to create an immutable and a mutable raw pointer from -references. +Listing 20-1 shows how to create an immutable and a mutable raw pointer. -+ ```rust {{#rustdoc_include ../listings/ch20-advanced-features/listing-20-01/src/main.rs:here}} @@ -105,9 +104,9 @@ unsafe block, as you’ll see in a bit. We’ve created raw pointers by using the raw borrow operators: `&raw const num` creates a `*const i32` immutable raw pointer, and `&raw mut num` creates a `&mut -i32` mutable raw pointer. Because we created them directly from references -guaranteed to be valid, we know these particular raw pointers are valid, but we -can’t make that assumption about just any raw pointer. +i32` mutable raw pointer. Because we created them directly from a local +variable, we know these particular raw pointers are valid, but we can’t make +that assumption about just any raw pointer. To demonstrate this, next we’ll create a raw pointer whose validity we can’t be so certain of, using `as` to cast a value instead of using the raw reference