3 ms·
> I’m not sure if the ownership rule is actually helpful in single-threaded contexts, but it at least makes sense in light of Rust’s green-threaded heritage. I
by pcwalton 12y ago
> I’m not sure if the ownership rule is actually helpful in single-threaded contexts, but it at least makes sense in light of Rust’s green-threaded heritage.
It's necessary for prevention of use-after-free. Here's a simple example (which can be translated into the equivalent C++):
let mut vector = vec![
"1".to_owned(),
"2".to_owned(),
"3".to_owned(),
];
for element in vector.iter() {
vector.clear();
println!("{}", element);
}