rust 中的 'static 约束

rust - What is the meaning of 'static as a function constraint? - Stack Overflow

fn foo<F: T + 'static>(f: F) {}

在类型约束中的生命周期泛型表示该类型的所有生命周期泛型参数都必须满足生命周期约束. 比如, 如下结构体

struct Kate<'a, 'b> {
    address: &'a str,
    lastname: &'b str,
}

Kate<'a, 'b> 只有在 'a = 'static'b='static 时满足 F: 'static.

对于没有生命周期泛型的结构体来说, 它们满足任何的生命周期约束.

F: 'static 意味着:

  • F 没有生命周期泛型参数
  • 所有的生命周期参数都是 'static