Function receiving and returning one reference
- the elision rules apply and thus we don't need lifetime specifiers
examples/lifetime/function-one-param/src/main.rs
fn main() { let mut x = String::new(); println!("{x}"); x = String::from("before"); println!("{x}"); let c = select(&x); x = String::from("after"); println!("{}", c); println!("{}", x); } //fn select(text: &str) -> &str { //fn select<'a>(text: &'a str) -> &'a str { //fn select<'a, 'b>(text: &'a str) -> &'b str { fn select(text: &str) -> &'static str { if text > "abc" { "first" } else { "second" } } // fn select(text: &str) -> &str { // //fn select<'a>(text: &'a str) -> &'a str { // //fn select<'a, 'b>(text: &'a str) -> &'b str { // //fn select(text: &str) -> &'static str { // if text > "abc" { // text // } else { // "second" // } // }
Foo Foo