鉴于以下防 rust 程序:
struct Value<'v>(&'v ());
struct Container {}
impl Container {
fn get<'v>(&'v self) -> Value<'v> {
todo!()
}
fn set<'v>(&'v self, x: Value<'v>) {
todo!()
}
}
fn convert<'v1, 'v2>(x: &'v1 Container, env: &'v2 Container) {
let root: Value<'v2> = env.get();
x.set(root);
}
我认为convert
是编译时错误,因为Value<'v2>
被传递到x.set()
,这需要Value<'v1>
类型的值——但它成功编译了.'v1
和'v2
之间没有亚型关系. rust 是如何在你的一生中得到满足的?