What's the difference between
let book_scores = &system.book_scores;
library.books.sort_unstable_by_key(|b| book_scores[*b]);
and
library.books.sort_unstable_by_key(|b| &system.book_scores[*b]);
?
The first one is allowed by the compiler and the second one fails with
error[E0502]: cannot borrow
system
as immutable because it is also borrowed as mutable
libraries
is a field of system
, library
is an element of libraries
in a for loop like
for library in &mut system.libraries {