这段代码编译和工作,但根据我的理解,它不应该编译:
use std::fmt::Display;
pub fn test<S>(s: S)
where
S: Display + 'static,
{
println!("test: {}", s);
}
fn main() {
let s = String::from("string");
test(s);
}
Run Code Online (Sandbox Code Playgroud)
变量的生命周期s是main,但函数必须test有一个界限.我认为变量的生命周期必须大于或大于.我的推理有什么问题?S'statics'static'static
rust ×1