From ddc7ef67cf61f50f842b20b6e5faeff8ffe7ad9e Mon Sep 17 00:00:00 2001 From: Filippo Casarin Date: Wed, 13 Nov 2024 22:48:49 +0100 Subject: [PATCH] [task.yaml.orig] user_io defaults to std_io --- .../src/ioi/dag/task_type/communication.rs | 15 +++++++++++++++ .../src/ioi/format/italian_yaml/mod.rs | 15 +++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/task-maker-format/src/ioi/dag/task_type/communication.rs b/task-maker-format/src/ioi/dag/task_type/communication.rs index 960c44eee..c149aed88 100644 --- a/task-maker-format/src/ioi/dag/task_type/communication.rs +++ b/task-maker-format/src/ioi/dag/task_type/communication.rs @@ -13,6 +13,7 @@ use crate::{EvaluationData, SourceFile, Tag}; /// The type of communication for the solution in a communication task. #[derive(Debug, Clone, Copy, Serialize, Deserialize, TypeScriptify, Eq, PartialEq)] +#[serde(rename_all = "snake_case")] pub enum UserIo { /// Communication is achieved by using stdin/stdout. StdIo, @@ -20,6 +21,20 @@ pub enum UserIo { FifoIo, } +impl UserIo { + /// Used for deserialization. + /// Returns UserIo::StdIo. + pub fn std_io() -> Self { + UserIo::StdIo + } + + /// Used for deserialization. + /// Returns UserIo::FifoIo. + pub fn fifo_io() -> Self { + UserIo::FifoIo + } +} + /// The internal data of a task of type `Batch`. #[derive(Debug, Clone, Serialize, Deserialize, TypeScriptify)] pub struct CommunicationTypeData { diff --git a/task-maker-format/src/ioi/format/italian_yaml/mod.rs b/task-maker-format/src/ioi/format/italian_yaml/mod.rs index 8f3aac600..95b565b9a 100644 --- a/task-maker-format/src/ioi/format/italian_yaml/mod.rs +++ b/task-maker-format/src/ioi/format/italian_yaml/mod.rs @@ -382,7 +382,8 @@ struct TaskYAML { /// /// Can be either "std_io" for using stdin/stdout, or "fifo_io" for using pipes given in argv. /// Defaults to "fifo_io". - pub user_io: Option, + #[serde(default = "UserIo::fifo_io")] + pub user_io: UserIo, /// Compatibility with cms, unused. pub score_mode: Option, @@ -437,7 +438,8 @@ struct TaskYAMLOrig { /// /// Can be either "std_io" for using stdin/stdout, or "fifo_io" for using pipes given in argv. /// Defaults to "fifo_io". - pub user_io: Option, + #[serde(default = "UserIo::std_io")] + pub user_io: UserIo, } impl TaskYAMLOrig { @@ -864,17 +866,10 @@ fn parse_communication_task_data( // Link the manager statically. This makes sure that it will work also outside this machine. manager.link_static(); - let user_io = match yaml.user_io.as_deref() { - None => UserIo::FifoIo, - Some("std_io") => UserIo::StdIo, - Some("fifo_io") => UserIo::FifoIo, - Some(other) => bail!("Unsupported value \"{}\" for user_io in task.yaml", other), - }; - Ok(Some(TaskType::Communication(CommunicationTypeData { manager: Arc::new(manager), num_processes: yaml.num_processes.unwrap_or(1), - user_io, + user_io: yaml.user_io, }))) }