use std::pin::Pin;
fn print_type_of<T>(_: &T) {
println!("{}", std::any::type_name::<T>())
}
fn test(s: String) {}
fn test2(s: Pin<&mut String>) {}
fn main() {
let s = String::from("abc");
print_type_of(&s);
tokio::pin!(s);
print_type_of(&s);
// test(s); error!
test2(s);
}
问题不在于为什么Pin
是什么,或者为什么需要Pin
.
呼叫tokio::pin!
后,s
的类型从alloc::string::String
变为core::pin::Pin<&mut alloc::string::String>
.这怎么会发生呢?更改宏内的外部变量的类型让我感到惊讶.