Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

生命周期

语法: ' 单引号开头 :&'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
    }
}
}