]> git.proxmox.com Git - rustc.git/blame - src/doc/book/listings/ch10-generic-types-traits-and-lifetimes/listing-10-21/src/main.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / doc / book / listings / ch10-generic-types-traits-and-lifetimes / listing-10-21 / src / main.rs
CommitLineData
74b04a01
XL
1fn main() {
2 let string1 = String::from("abcd");
3 let string2 = "xyz";
4
5 let result = longest(string1.as_str(), string2);
6 println!("The longest string is {}", result);
7}
8
9// ANCHOR: here
923072b8 10fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
74b04a01
XL
11 if x.len() > y.len() {
12 x
13 } else {
14 y
15 }
16}
17// ANCHOR_END: here