zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    例7-13
    例7-11
    例7-1
    例6-5
    例6-3
    例6-2
    例6-1
    例5-9
    例5-8
    例5-7
  • 原文地址:https://www.cnblogs.com/wbin91/p/14245205.html
Copyright © 2011-2022 走看看