我想讀一個文件並返回它作爲一個UTF-8
std:string:String
好像content
是Result<collections::string::String, collections::vec::Vec<u8>>
如果我沒有理解錯誤信息,我從嘗試String::from_utf8(content)
了。鏽創建file.read_to_end一個String()
fn get_index_body() -> String {
let path = Path::new("../html/ws1.html");
let display = path.display();
let mut file = match File::open(&path) {
Ok(f) => f,
Err(err) => panic!("file error: {}", err)
};
let content = file.read_to_end();
println!("{} {}", display, content);
return String::new(); // how to turn into String (which is utf-8)
}
你會說'let s = String :: from_utf8(content).unwrap();'是在我返回之前將內容轉換爲'String'的好方法嗎?我的意思是使用的資源。 – Victory 2014-11-23 21:54:50