Rust 读取文件内容

use std::error::Error;
use std::fs::File;
use std::io::Read;

pub fn read_file(path: &str) -> Result<String, Box<dyn Error>> {
    let mut content = String::new();
    File::open(path)?.read_to_string(&mut content)?;
    return Ok(content);
}

posted @ 2023-03-01 15:27  gcvition  阅读(52)  评论(0)    收藏  举报