mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 15:26:29 +00:00
Preallocate path
This commit is contained in:
parent
ef02c6c6ab
commit
edf5762612
1 changed files with 12 additions and 3 deletions
|
@ -43,7 +43,13 @@ struct ExerciseDir {
|
|||
|
||||
impl ExerciseDir {
|
||||
fn init_on_disk(&self) -> Result<()> {
|
||||
let dir_path = format!("exercises/{}", self.name);
|
||||
let path_prefix = "exercises/";
|
||||
let readme_path_postfix = "/README.md";
|
||||
let mut dir_path =
|
||||
String::with_capacity(path_prefix.len() + self.name.len() + readme_path_postfix.len());
|
||||
dir_path.push_str(path_prefix);
|
||||
dir_path.push_str(self.name);
|
||||
|
||||
if let Err(e) = create_dir(&dir_path) {
|
||||
if e.kind() == io::ErrorKind::AlreadyExists {
|
||||
return Ok(());
|
||||
|
@ -54,8 +60,11 @@ impl ExerciseDir {
|
|||
);
|
||||
}
|
||||
|
||||
WriteStrategy::Overwrite
|
||||
.write(&format!("exercises/{}/README.md", self.name), self.readme)?;
|
||||
let readme_path = {
|
||||
dir_path.push_str(readme_path_postfix);
|
||||
dir_path
|
||||
};
|
||||
WriteStrategy::Overwrite.write(&readme_path, self.readme)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue