mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-06 01:53:30 +02:00
Use sol_path
This commit is contained in:
@@ -68,6 +68,7 @@ pub struct Exercise {
|
||||
|
||||
pub trait RunnableExercise {
|
||||
fn name(&self) -> &str;
|
||||
fn dir(&self) -> Option<&str>;
|
||||
fn strict_clippy(&self) -> bool;
|
||||
fn test(&self) -> bool;
|
||||
|
||||
@@ -145,6 +146,31 @@ pub trait RunnableExercise {
|
||||
|
||||
self.run::<true>(&bin_name, output, cmd_runner)
|
||||
}
|
||||
|
||||
fn sol_path(&self) -> String {
|
||||
let name = self.name();
|
||||
|
||||
let mut path = if let Some(dir) = self.dir() {
|
||||
// 14 = 10 + 1 + 3
|
||||
// solutions/ + / + .rs
|
||||
let mut path = String::with_capacity(14 + dir.len() + name.len());
|
||||
path.push_str("solutions/");
|
||||
path.push_str(dir);
|
||||
path.push('/');
|
||||
path
|
||||
} else {
|
||||
// 13 = 10 + 3
|
||||
// solutions/ + .rs
|
||||
let mut path = String::with_capacity(13 + name.len());
|
||||
path.push_str("solutions/");
|
||||
path
|
||||
};
|
||||
|
||||
path.push_str(name);
|
||||
path.push_str(".rs");
|
||||
|
||||
path
|
||||
}
|
||||
}
|
||||
|
||||
impl RunnableExercise for Exercise {
|
||||
@@ -153,6 +179,11 @@ impl RunnableExercise for Exercise {
|
||||
self.name
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn dir(&self) -> Option<&str> {
|
||||
self.dir
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn strict_clippy(&self) -> bool {
|
||||
self.strict_clippy
|
||||
|
||||
Reference in New Issue
Block a user