Make great things

What I cannot create, I do not understand.

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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
posted on 2021-01-07 10:50  wbin91  阅读(3026)  评论(0编辑  收藏  举报