相关疑难解决方法(0)

如何从Rust中的文件中读取结构?

有没有办法可以直接从Rust的文件中读取结构?我的代码是:

use std::fs::File;

struct Configuration {
    item1: u8,
    item2: u16,
    item3: i32,
    item4: [char; 8],
}

fn main() {
    let file = File::open("config_file").unwrap();

    let mut config: Configuration;
    // How to read struct from file?
}
Run Code Online (Sandbox Code Playgroud)

我如何直接config从文件中读取配置?这甚至可能吗?

io rust

15
推荐指数
3
解决办法
8023
查看次数

标签 统计

io ×1

rust ×1