@@ -194,35 +194,53 @@ mod file {
194194 use crate :: { cache:: models:: Problem , Error } ;
195195
196196 /// Generate test cases path by fid
197- pub fn test_cases_path ( problem : & Problem ) -> crate :: Result < String > {
198- let conf = crate :: config:: Config :: locate ( ) ?;
199- let mut path = format ! ( "{}/{}.tests.dat" , conf. storage. code( ) ?, conf. code. pick) ;
197+ pub fn test_cases_path ( problem : & Problem ) -> crate :: Result < String > {
198+ let conf = crate :: config:: Config :: locate ( ) ?;
199+ let lang = conf. code . lang . clone ( ) ;
200+ let code_base = conf. storage . code ( ) ?;
200201
202+ let path = if lang == "rust" {
203+ let sanitized_slug = problem. slug . replace ( |c : char | !c. is_alphanumeric ( ) , "_" ) ;
204+ let subdir = format ! ( "{}-{}/tests.dat" , problem. fid, sanitized_slug) ;
205+ format ! ( "{}/{}" , code_base, subdir)
206+ } else {
207+ let mut path = format ! ( "{}/{}.tests.dat" , code_base, conf. code. pick) ;
201208 path = path. replace ( "${fid}" , & problem. fid . to_string ( ) ) ;
202209 path = path. replace ( "${slug}" , & problem. slug . to_string ( ) ) ;
203- Ok ( path)
204- }
210+ path
211+ } ;
212+
213+ Ok ( path)
214+ }
205215
206216 /// Generate code path by fid
207- pub fn code_path ( problem : & Problem , l : Option < String > ) -> crate :: Result < String > {
208- let conf = crate :: config:: Config :: locate ( ) ?;
209- let mut lang = conf. code . lang ;
210- if l. is_some ( ) {
211- lang = l. ok_or ( Error :: NoneError ) ?;
212- }
217+ pub fn code_path ( problem : & Problem , l : Option < String > ) -> crate :: Result < String > {
218+ let conf = crate :: config:: Config :: locate ( ) ?;
219+ let mut lang = conf. code . lang . clone ( ) ;
220+ if let Some ( lang_opt) = l {
221+ lang = lang_opt;
222+ }
223+
224+ let code_base = conf. storage . code ( ) ?;
213225
226+ let path = if lang == "rust" {
227+ let sanitized_slug = problem. slug . replace ( |c : char | !c. is_alphanumeric ( ) , "_" ) ;
228+ let subdir = format ! ( "{}-{}/src/lib.rs" , problem. fid, sanitized_slug) ;
229+ format ! ( "{}/{}" , code_base, subdir)
230+ } else {
214231 let mut path = format ! (
215232 "{}/{}.{}" ,
216- conf . storage . code ( ) ? ,
233+ code_base ,
217234 conf. code. pick,
218235 suffix( & lang) ?,
219236 ) ;
220-
221237 path = path. replace ( "${fid}" , & problem. fid . to_string ( ) ) ;
222238 path = path. replace ( "${slug}" , & problem. slug . to_string ( ) ) ;
239+ path
240+ } ;
223241
224- Ok ( path)
225- }
242+ Ok ( path)
243+ }
226244
227245 /// Load python scripts
228246 pub fn load_script ( module : & str ) -> crate :: Result < String > {
0 commit comments