Skip to content

Instantly share code, notes, and snippets.

@jw3126
Created April 20, 2018 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jw3126/d05d065a33312723629f78305ba5e03a to your computer and use it in GitHub Desktop.
Save jw3126/d05d065a33312723629f78305ba5e03a to your computer and use it in GitHub Desktop.
Simple lifetime example
use std::path::{Path};
fn create_path<'a>(s: &'a String)->&'a Path { // return value has the same lifetime as input
Path::new(s)
}
fn main() {
let s = "some/path".to_string();
let p = create_path(&s);
println!("{:?}", p)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment