【发布时间】:2021-10-16 17:22:33
【问题描述】:
我想将整个目录复制到用户$HOME 中的某个位置。将文件单独复制到该目录很简单:
let contents = include_str!("resources/profiles/default.json");
let fpath = dpath.join(&fname);
fs::write(fpath, contents).expect(&format!("failed to create profile: {}", n));
我还没有找到一种方法来适应多个文件:
for n in ["default"] {
let fname = format!("{}{}", n, ".json");
let x = format!("resources/profiles/{}", fname).as_str();
let contents = include_str!(x);
let fpath = dpath.join(&fname);
fs::write(fpath, contents).expect(&format!("failed to create profile: {}", n));
}
...编译器抱怨x 必须是字符串文字。
据我所知,有两种选择:
- 编写自定义宏。
- 为我要复制的每个文件复制第一个代码。
最好的方法是什么?
【问题讨论】:
标签: rust