mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-22 14:02:22 -05: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 {
|
impl ExerciseDir {
|
||||||
fn init_on_disk(&self) -> Result<()> {
|
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 let Err(e) = create_dir(&dir_path) {
|
||||||
if e.kind() == io::ErrorKind::AlreadyExists {
|
if e.kind() == io::ErrorKind::AlreadyExists {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -54,8 +60,11 @@ impl ExerciseDir {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteStrategy::Overwrite
|
let readme_path = {
|
||||||
.write(&format!("exercises/{}/README.md", self.name), self.readme)?;
|
dir_path.push_str(readme_path_postfix);
|
||||||
|
dir_path
|
||||||
|
};
|
||||||
|
WriteStrategy::Overwrite.write(&readme_path, self.readme)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue