Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
- if x.len() > y.len() {
- x
- } else {
- y
- }
- }
- fn main() {
- // lifetime 'a
- let s1 = "asdas".to_string();
- // lifetime 'a (like return type of longest func)
- let result;
- {
- // lifetime 'b
- let s2 = "hello wrlld".to_string();
- // 'a 'b
- result = longest(&s1, &s2);
- // cannot to that
- }
- println!("result: {}", result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement