summaryrefslogtreecommitdiff
path: root/rust/theBook/chapter-10-generic-types-traits-lifetimes/lifetimes/src/main.rs
blob: af88f352084abba53c5887473c99e84526a496e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
    if x.len() < y.len() {
        y
    }   else {
        x
    }
}

struct ImportantExcerpt<'a> {
    part: &'a str,
}

fn main() {
    let x = String::from("abcd");
    let result;
    let y = String::from("x7z");
    result = longest(x.as_str(), y.as_str());
    println!("The longest string is {}", result);
}