在当前范围内找不到结构体“File”名为“read_to_string”的方法

scr*_*ius 2 rust

我正在尝试将文件读入字符串,但出现编译器错误,并显示消息“错误[E0599]:在当前范围内没有read_to_string为结构找到名为的方法”File

无法理解我做错了什么。下面是有问题的代码:

impl Todo {
    fn new() -> Result<Todo, std::io::Error> {
        let mut content = String::new();

        std::fs::OpenOptions::new()
            .read(true)
            .write(true)
            .create(true)
            .open("todo.txt")?
            .read_to_string(&mut content)?
       
    }
}
Run Code Online (Sandbox Code Playgroud)

版本: 货物:1.56.0 rustc:1.56.1 rustup:1.24.3