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:
706bf6c
)
fix some language
author
Ralf Jung
<post@ralfj.de>
Wed, 4 May 2016 18:28:22 +0000
(20:28 +0200)
committer
Ralf Jung
<post@ralfj.de>
Wed, 4 May 2016 18:28:22 +0000
(20:28 +0200)
src/part04.rs
patch
|
blob
|
history
diff --git
a/src/part04.rs
b/src/part04.rs
index f2a6b6c9417689f79e676d50604672db3d0ec2fe..dc116ee3ab54b505b632d298a861fcbfe9beed74 100644
(file)
--- a/
src/part04.rs
+++ b/
src/part04.rs
@@
-50,9
+50,9
@@
fn ownership_demo() {
//@ we wanted! Can't we somehow give `vec_min` access to the vector, while retaining ownership of it?
//@
//@ Rust calls this *a reference* the vector, and it considers references as *borrowing* ownership. This
//@ we wanted! Can't we somehow give `vec_min` access to the vector, while retaining ownership of it?
//@
//@ Rust calls this *a reference* the vector, and it considers references as *borrowing* ownership. This
-//@ works a bit like borrowing does in the real world: If you
borrow a book to your friend
, your friend
+//@ works a bit like borrowing does in the real world: If you
r friend borrows a book from you
, your friend
//@ can have it and work on it (and you can't!) as long as the book is still borrowed. Your friend could
//@ can have it and work on it (and you can't!) as long as the book is still borrowed. Your friend could
-//@ even
borrow
the book to someone else. Eventually however, your friend has to give the book back to you,
+//@ even
lend
the book to someone else. Eventually however, your friend has to give the book back to you,
//@ at which point you again have full control.
//@
//@ Rust distinguishes between two kinds of references. First of all, there's the *shared* reference.
//@ at which point you again have full control.
//@
//@ Rust distinguishes between two kinds of references. First of all, there's the *shared* reference.
@@
-88,7
+88,7
@@
fn shared_ref_demo() {
vec_min(&v);
println!("The first element is: {}", *first);
}
vec_min(&v);
println!("The first element is: {}", *first);
}
-//@ What's going on here? First, `&` is how you
borrow
ownership to someone - this operator creates a shared reference.
+//@ What's going on here? First, `&` is how you
lend
ownership to someone - this operator creates a shared reference.
//@ `shared_ref_demo` creates three shared references to `v`:
//@ The reference `first` begins in the 2nd line of the function and lasts all the way to the end. The other two
//@ references, created for calling `vec_min`, only last for the duration of that respective call.
//@ `shared_ref_demo` creates three shared references to `v`:
//@ The reference `first` begins in the 2nd line of the function and lasts all the way to the end. The other two
//@ references, created for calling `vec_min`, only last for the duration of that respective call.