From 5556d42b46e3bfe281343d69da588378c728c089 Mon Sep 17 00:00:00 2001 From: mo8it Date: Wed, 28 Aug 2024 01:10:19 +0200 Subject: Use sol_path --- src/exercise.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/exercise.rs') 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::(&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 -- cgit v1.2.3