summaryrefslogtreecommitdiff
path: root/src/exercise.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-08-28 01:10:19 +0200
committermo8it <mo8it@proton.me>2024-08-28 01:10:19 +0200
commit5556d42b46e3bfe281343d69da588378c728c089 (patch)
tree66583d0250efb3e4532141e457bff2a3b5d9d325 /src/exercise.rs
parent7d2bc1c7a4333de5460cb86a8dca5e5ecad2a643 (diff)
Use sol_path
Diffstat (limited to 'src/exercise.rs')
-rw-r--r--src/exercise.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/exercise.rs b/src/exercise.rs
index ea15465..11eea63 100644
--- a/src/exercise.rs
+++ b/src/exercise.rs
@@ -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 {
@@ -154,6 +180,11 @@ impl RunnableExercise for Exercise {
}
#[inline]
+ fn dir(&self) -> Option<&str> {
+ self.dir
+ }
+
+ #[inline]
fn strict_clippy(&self) -> bool {
self.strict_clippy
}