projects
/
rust-101.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
79b3d41
)
more typos
author
Ralf Jung
<post@ralfj.de>
Fri, 28 Apr 2023 13:34:47 +0000
(15:34 +0200)
committer
GitHub
<noreply@github.com>
Fri, 28 Apr 2023 13:34:47 +0000
(15:34 +0200)
src/part06.rs
patch
|
blob
|
history
diff --git
a/src/part06.rs
b/src/part06.rs
index de90cb64e6a3236ad412881b61ebbf3607d74fda..4c7ee24fdeedfab73af6b88b05df989b37623297 100644
(file)
--- a/
src/part06.rs
+++ b/
src/part06.rs
@@
-127,7
+127,7
@@
fn head<T>(v: &Vec<T>) -> Option<&T> {
//@ have aliasing (of `first` and `v`) and mutation. But this time, the bug is hidden behind the
//@ call to `head`. How does Rust solve this? If we translate the code above to Rust, it doesn't
//@ compile, so clearly we are good - but how and why?
//@ have aliasing (of `first` and `v`) and mutation. But this time, the bug is hidden behind the
//@ call to `head`. How does Rust solve this? If we translate the code above to Rust, it doesn't
//@ compile, so clearly we are good - but how and why?
-//@ (Notice that
have to explicitly assert using `unwrap`
that `first` is not `None`, whereas
+//@ (Notice that
we use `unwrap` to explicitly assert
that `first` is not `None`, whereas
//@ the C++ code above would silently dereference a `NULL`-pointer. But that's another point.)
fn rust_foo(mut v: Vec<i32>) -> i32 {
let first: Option<&i32> = head(&v);
//@ the C++ code above would silently dereference a `NULL`-pointer. But that's another point.)
fn rust_foo(mut v: Vec<i32>) -> i32 {
let first: Option<&i32> = head(&v);