静态或const中`&str`和`&'static str`有什么区别?

Raj*_*jan 6 rust

我是Rust编程的新手,也是关于生命周期的学习.

const CONST_MEEP: &str = "MEEP";
const CONST_LIFETIME_MEEP: &'static str = "MEEP";
static STATIC_MEEP: &'static str = "MEEP";
static STATIC_LIFETIME_MEEP: &str = "MEEP";

fn main() {
    println!("CONST_MEEP is {}", CONST_MEEP);
    println!("CONST_LIFETIME_MEEP is {}", CONST_LIFETIME_MEEP);
    println!("STATIC_MEEP is {}", STATIC_MEEP);
    println!("STATIC_LIFETIME_MEEP is {}", STATIC_LIFETIME_MEEP);
}
Run Code Online (Sandbox Code Playgroud)

输出:

CONST_MEEP is MEEP
CONST_LIFETIME_MEEP is MEEP
STATIC_MEEP is MEEP
STATIC_LIFETIME_MEEP is MEEP
Run Code Online (Sandbox Code Playgroud)

CONST_MEEP和之间有什么区别CONST_LIFETIME_MEEPSTATIC_MEEP和之间有什么区别STATIC_LIFETIME_MEEP

She*_*ter 9

没什么,没有区别.从RFC 1623开始,引用staticconst项目是自动的'static.这在Rust 1.17中生效.