<예제 코드_1>
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
x
} else {
y
}
}
fn main() {
let string1 = String::from("abcd");
let string2 = "xyz";
let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
}
<참조 1> https://rinthel.github.io/rust-lang-book-ko/ch10-03-lifetime-syntax.html
<참조 2>
'Rust' 카테고리의 다른 글
[Rust] Testing 예제_2 (27일차) (0) | 2023.01.09 |
---|---|
[Rust] Testing 예제 (26일차) (0) | 2023.01.08 |
[Rust] Trait 예제 (24일차) (0) | 2023.01.06 |
[Rust] Generic : Data Type 예제 (23일차) (0) | 2023.01.05 |
댓글