Skip to content

Commit 96981de

Browse files
author
Antonio Bennett
committed
Feature: Make Rust crate generation configurable
- Add [code] enable_rust_crates = true (default) in config. - Allows opting out of subdir structure for Rust. - Updates paths and creation logic accordingly. - Fix serde attribute for the new field.
1 parent e9e1f36 commit 96981de

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/cmds/edit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ use std::path::Path;
108108

109109
let question: Question = qr?;
110110

111-
if *lang == "rust" {
111+
if *lang == "rust" && conf.code.enable_rust_crates {
112112
let flat_suffix = suffix(&lang).map_err(anyhow::Error::msg)?; // Since suffix returns Result<&str>
113113
let pick_replaced = conf.code.pick.replace("${fid}", &problem.fid.to_string()).replace("${slug}", &problem.slug.to_string());
114114
let flat_path_str = format!("{}/{}.{}", conf.storage.code()?, pick_replaced, flat_suffix);

src/config/code.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ fn default_submission() -> String {
99
"${fid}.${slug}.${sid}.${ac}".into()
1010
}
1111

12+
fn default_enable_rust_crates() -> bool {
13+
true
14+
}
15+
1216
/// Code config
1317
#[derive(Clone, Debug, Deserialize, Serialize)]
1418
pub struct Code {
@@ -34,6 +38,7 @@ pub struct Code {
3438
pub comment_leading: String,
3539
#[serde(default, skip_serializing)]
3640
pub test: bool,
41+
pub enable_rust_crates: bool,
3742
pub lang: String,
3843
#[serde(default = "default_pick", skip_serializing)]
3944
pub pick: String,
@@ -55,6 +60,7 @@ impl Default for Code {
5560
comment_problem_desc: false,
5661
comment_leading: "".into(),
5762
test: true,
63+
enable_rust_crates: default_enable_rust_crates(),
5864
lang: "rust".into(),
5965
pick: "${fid}.${slug}".into(),
6066
submission: "${fid}.${slug}.${sid}.${ac}".into(),

src/helper.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,10 @@ mod file {
197197
pub fn test_cases_path(problem: &Problem) -> crate::Result<String> {
198198
let conf = crate::config::Config::locate()?;
199199
let lang = conf.code.lang.clone();
200+
let use_crates = conf.code.enable_rust_crates;
200201
let code_base = conf.storage.code()?;
201202

202-
let path = if lang == "rust" {
203+
let path = if lang == "rust" && use_crates {
203204
let sanitized_slug = problem.slug.to_lowercase().replace(|c: char| !c.is_alphanumeric(), "_");
204205
let subdir = format!("{}-{}/tests.dat", problem.fid, sanitized_slug);
205206
format!("{}/{}", code_base, subdir)
@@ -221,9 +222,10 @@ pub fn code_path(problem: &Problem, l: Option<String>) -> crate::Result<String>
221222
lang = lang_opt;
222223
}
223224

225+
let use_crates = conf.code.enable_rust_crates;
224226
let code_base = conf.storage.code()?;
225227

226-
let path = if lang == "rust" {
228+
let path = if lang == "rust" && use_crates {
227229
let sanitized_slug = problem.slug.to_lowercase().replace(|c: char| !c.is_alphanumeric(), "_");
228230
let subdir = format!("{}-{}/src/lib.rs", problem.fid, sanitized_slug);
229231
format!("{}/{}", code_base, subdir)

0 commit comments

Comments
 (0)