Lifetimes in Rust
Occasionally I've found myself wanting to write functions that can be called in either of two ways: // With a string literal: let lines = read_file_lines("data.txt"); // With a string pointer: let file_name = ~"data.txt"; let lines = read_file_lines(file_name); My first guess was to use a borrowed pointer ( &str ) for the parameter type, but when that didn't work (it only allowed me to use @str and ~str ), I tried the following (by copying the Rust libraries), which did work. fn read_file_lines<'a>(path: &'a str) -> ~[~str] { let read_result = file_reader(~Path(path)); match read_result { Ok