@@ -26,8 +26,10 @@ use walkdir::WalkDir;
2626/// Implementations must be thread-safe and preferably fully stateless. Users of
2727/// this interface are free to cache results if needed.
2828pub trait LanguagePlugin {
29+ type StudentFilePolicy : StudentFilePolicy + ' static ;
30+
2931 /// Returns the name of the plug-in.
30- fn get_plugin_name ( & self ) -> & str ;
32+ fn get_plugin_name ( ) -> & ' static str ;
3133
3234 /// Returns a list of all directories inside that contain an exercise in this
3335 /// language.
@@ -43,7 +45,7 @@ pub trait LanguagePlugin {
4345 . filter_entry ( |e| e. path ( ) . is_dir ( ) )
4446 . filter_map ( |e| e. ok ( ) )
4547 {
46- if self . is_exercise_type_correct ( entry. path ( ) ) {
48+ if Self :: is_exercise_type_correct ( entry. path ( ) ) {
4749 debug ! ( "found exercise {}" , entry. path( ) . display( ) ) ;
4850 exercises. push ( entry. into_path ( ) ) ;
4951 }
@@ -63,8 +65,7 @@ pub trait LanguagePlugin {
6365
6466 /// Runs the tests for the exercise.
6567 fn run_tests ( & self , path : & Path ) -> Result < RunResult > {
66- let timeout = self
67- . get_student_file_policy ( path)
68+ let timeout = Self :: get_student_file_policy ( path)
6869 . get_tmc_project_yml ( )
6970 . ok ( )
7071 . and_then ( |t| t. tests_timeout_ms . map ( Duration :: from_millis) ) ;
@@ -82,7 +83,7 @@ pub trait LanguagePlugin {
8283 /// easily replace the tests.
8384 fn prepare_submission (
8485 & self ,
85- policy : Box < dyn StudentFilePolicy > ,
86+ policy : Self :: StudentFilePolicy ,
8687 submission_path : & Path ,
8788 dest_path : & Path ,
8889 ) -> Result < ( ) > {
@@ -124,24 +125,24 @@ pub trait LanguagePlugin {
124125
125126 /// Compress a given project so that it can be sent to the TestMyCode server.
126127 fn compress_project ( & self , path : & Path ) -> Result < Vec < u8 > > {
127- let policy = self . get_student_file_policy ( path) ;
128- Ok ( zip:: zip ( policy, path) ?)
128+ let policy = Self :: get_student_file_policy ( path) ;
129+ Ok ( zip:: zip ( Box :: new ( policy) , path) ?)
129130 }
130131
131- fn get_student_file_policy ( & self , project_path : & Path ) -> Box < dyn StudentFilePolicy > ;
132+ fn get_student_file_policy ( project_path : & Path ) -> Self :: StudentFilePolicy ;
132133
133134 /// Extract a given archive file containing a compressed project to a target location.
134135 ///
135136 /// This will overwrite any existing files as long as they are not specified as student files
136137 /// by the language dependent student file policy.
137138 fn extract_project ( & self , compressed_project : & Path , target_location : & Path ) -> Result < ( ) > {
138- let policy = self . get_student_file_policy ( target_location) ;
139+ let policy = Self :: get_student_file_policy ( target_location) ;
139140 zip:: unzip ( policy, compressed_project, target_location) ?;
140141 Ok ( ( ) )
141142 }
142143
143144 /// Tells if there's a valid exercise in this path.
144- fn is_exercise_type_correct ( & self , path : & Path ) -> bool ;
145+ fn is_exercise_type_correct ( path : & Path ) -> bool ;
145146
146147 /// Copy shared stuff to stub or solution used for example for copying tmc-junit-runner.
147148 #[ allow( unused_variables) ]
@@ -206,11 +207,13 @@ mod test {
206207 }
207208
208209 impl LanguagePlugin for MockPlugin {
209- fn get_student_file_policy ( & self , _project_path : & Path ) -> Box < dyn StudentFilePolicy > {
210+ type StudentFilePolicy = MockPolicy ;
211+
212+ fn get_student_file_policy ( project_path : & Path ) -> Self :: StudentFilePolicy {
210213 unimplemented ! ( )
211214 }
212215
213- fn get_plugin_name ( & self ) -> & ' static str {
216+ fn get_plugin_name ( ) -> & ' static str {
214217 unimplemented ! ( )
215218 }
216219
@@ -226,7 +229,7 @@ mod test {
226229 unimplemented ! ( )
227230 }
228231
229- fn is_exercise_type_correct ( & self , path : & Path ) -> bool {
232+ fn is_exercise_type_correct ( path : & Path ) -> bool {
230233 !path. to_str ( ) . unwrap ( ) . contains ( "ignored" )
231234 }
232235
0 commit comments