const fn get_dockerfile() -> String {
let mut file_content = String::new();
let mut file = File::open("dockers/PostgreSql").expect("Failed to read the file");
file.read_to_string(&mut file_content);
file_content
}
const DOCKERFILE: String = get_dockerfile();
我正在编写一个Rust脚本来管理Docker操作。
- 我希望在我的二进制可执行文件中包含docker文件内容。
- 我认为通过将这个内容分配到一个
const
变量中,我可以实现这个目标,但是我遇到了这个错误:
error[E0723]: mutable references in const fn are unstable
--> src/main.rs:9:5
|
9 | file.read_to_string(&mut file_content);