X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/d377bcf41f66436b2f43771910dc8fae1a3cff6a..1b77423cf168e5ff2b41667ea67252f4fbc44652:/src/part07.rs diff --git a/src/part07.rs b/src/part07.rs index a996a22..65d6823 100644 --- a/src/part07.rs +++ b/src/part07.rs @@ -27,9 +27,7 @@ pub fn vec_min(v: &Vec) -> Option<&T> { // Notice that the return type `Option<&T>` is technically (leaving the borrowing story aside) a // pointer to a `T`, that could optionally be invalid. In other words, it's just like a pointer in // C(++) or Java that can be `NULL`! However, thanks to `Option` being an `enum`, we cannot forget -// to check the pointer for validity, avoiding the safety issues of C(++). At the same time, when we -// have a borrow like `v` above that's not an `Option`, we *know* that is has to be a valid -// pointer, so we don't even need to do the `NULL`-check that Java does all the time.
+// to check the pointer for validity, avoiding the safety issues of C(++).
// Also, if you are worried about wasting space, notice that Rust knows that `&T` can never be // `NULL`, and hence optimizes `Option<&T>` to be no larger than `&T`. The `None` case is represented // as `NULL`. This is another great example of a zero-cost abstraction: `Option<&T>` is exactly like