File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ mod tests {
108
108
ExerciseInfo {
109
109
name : String :: from ( "1" ) ,
110
110
dir : None ,
111
+ module_file : None ,
111
112
test : true ,
112
113
strict_clippy : true ,
113
114
hint : String :: new ( ) ,
@@ -116,6 +117,7 @@ mod tests {
116
117
ExerciseInfo {
117
118
name : String :: from ( "2" ) ,
118
119
dir : Some ( String :: from ( "d" ) ) ,
120
+ module_file : None ,
119
121
test : false ,
120
122
strict_clippy : false ,
121
123
hint : String :: new ( ) ,
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ pub struct ExerciseInfo {
11
11
pub name : String ,
12
12
/// Exercise's directory name inside the `exercises/` directory.
13
13
pub dir : Option < String > ,
14
+ /// Extra one Aditional Module file
15
+ #[ serde( default ) ]
16
+ pub module_file : Option < String > ,
14
17
/// Run `cargo test` on the exercise.
15
18
#[ serde( default = "default_true" ) ]
16
19
pub test : bool ,
@@ -52,6 +55,33 @@ impl ExerciseInfo {
52
55
53
56
path
54
57
}
58
+
59
+ pub fn module_file_path ( & self ) -> Option < String > {
60
+ if let Some ( module_path) = & self . module_file {
61
+ let mut path = if let Some ( dir) = & self . dir {
62
+ // 14 = 10 + 1 + 3
63
+ // exercises/ + / + .rs
64
+ let mut path = String :: with_capacity ( 14 + dir. len ( ) + module_path. len ( ) ) ;
65
+ path. push_str ( "exercises/" ) ;
66
+ path. push_str ( dir) ;
67
+ path. push ( '/' ) ;
68
+ path
69
+ } else {
70
+ // 13 = 10 + 3
71
+ // exercises/ + .rs
72
+ let mut path = String :: with_capacity ( 13 + module_path. len ( ) ) ;
73
+ path. push_str ( "exercises/" ) ;
74
+ path
75
+ } ;
76
+
77
+ path. push_str ( & module_path) ;
78
+ path. push_str ( ".rs" ) ;
79
+
80
+ Some ( path)
81
+ } else {
82
+ None
83
+ }
84
+ }
55
85
}
56
86
57
87
impl RunnableExercise for ExerciseInfo {
You can’t perform that action at this time.
0 commit comments