You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Rust book (2018 edition) uses the following example in chapter 10 (comments added by me)
fnlargest(list:&[i32]) -> i32{letmut largest = list[0];// i32for&item in list.iter(){// item is &i32if item > largest {
largest = item;}}
largest
}
This was and still is puzzling to me for several reasons:
list is &[i32], so I'd expect list[0] to be &i32. Instead, list[0] is i32...
which is extra weird because list.iter() seems to yield &i32's.
Finally, what the heck is &item? I thought & made references, but here it seems to do the opposite.
I gather that there's some kind of implicit dereferencing going on when we do list[0], and I guess &item is also a dereference. It would be nice if this were explained in the book before it shows up in the example.
The text was updated successfully, but these errors were encountered:
The Rust book (2018 edition) uses the following example in chapter 10 (comments added by me)
This was and still is puzzling to me for several reasons:
list
is&[i32]
, so I'd expectlist[0]
to be&i32
. Instead,list[0]
isi32
...list.iter()
seems to yield&i32
's.&item
? I thought&
made references, but here it seems to do the opposite.I gather that there's some kind of implicit dereferencing going on when we do
list[0]
, and I guess&item
is also a dereference. It would be nice if this were explained in the book before it shows up in the example.The text was updated successfully, but these errors were encountered: