Read file contents to string safely
You could return the string directly:

fn main() {
    let file_name = "test.txt";
    let file_contents = match get_file_contents(file_name) {
        Ok(s) =&gt; s,
        Err(err) =&gt; panic!("{}", err)
    };

    println!("{}", file_contents);
}

fn get_file_contents(name: &amp;str) -&gt; Result&lt;String, io::Error&gt; {
    let mut f = try!(File::open(name));
    let mut contents = String::new();

    try!(f.read_to_string(&amp;mut contents));

    Ok(contents)
}


and unwrap if you don’t intend to handle the error usefully:

let file_contents = get_file_contents(file_name).unwrap();