生命周期
语法: ' 单引号开头 :&'a
#![allow(unused)] fn main() { #[test] fn live_test(){ let x = String::from("hello"); let y = "hi"; let z = live(&x[..=2],y); //&[..=2] println!("{}",z); } fn live<'c>(x: &'c str,y: &'c str) -> &'c str{ if x.len()>y.len(){ x } else { y } } }