When does function reborrow / move its argument? In the following example,
fn main() {
use std::str::FromStr;
let mut my_str: String = String::from_str("hello").unwrap();
let borrow_str: &mut String = &mut my_str;
foo(borrow_str);
println!("{}", borrow_str)
}
fn foo<T>(string: &mut T) {} // works. reborrows &mut String.
// fn foo<T>(string: T) {} // does not work. moves &mut String.
Why do they work differently?
Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b157c254f9a88efd69099dce1bb41de4