Skip to content

Commit

Permalink
feat(rsjudge-judger): ✨ try to implement judge request module
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Jul 18, 2024
1 parent 84f04f1 commit ca3cc08
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/rsjudge-judger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ rust-version.workspace = true

[dependencies]
async-trait = "0.1.81"
bytes = "1.6.1"
futures = "0.3.30"
rsjudge-traits.workspace = true
rsjudge-utils.workspace = true
tokio = { workspace = true, features = ["io-util", "fs", "macros"] }

Expand Down
4 changes: 2 additions & 2 deletions crates/rsjudge-judger/src/comparer/default_comparer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use futures::try_join;
use rsjudge_utils::trim_space_end;
use tokio::io::{AsyncBufReadExt as _, AsyncRead, BufReader};

use crate::{CompareResult, Comparer};
use crate::comparer::{CompareResult, Comparer};

/// A default comparer implementation with basic configurations.
#[must_use = "Comparer makes no sense if it is not used"]
Expand Down Expand Up @@ -123,7 +123,7 @@ mod tests {
io::{empty, AsyncWriteExt as _},
};

use crate::{CompareResult, Comparer as _, DefaultComparer};
use crate::comparer::{CompareResult, Comparer as _, DefaultComparer};

#[tokio::test]
async fn compare_empty() -> io::Result<()> {
Expand Down
1 change: 1 addition & 0 deletions crates/rsjudge-judger/src/judger/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod request;
31 changes: 31 additions & 0 deletions crates/rsjudge-judger/src/judger/request/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use bytes::Bytes;

use crate::judger::request::{source::Source, test_cases::TestCases};

mod source;

mod test_cases;

pub struct JudgeRequest {
source: Source,
judge_type: JudgeType,
}

impl JudgeRequest {
pub fn new(source: Source, judge_type: JudgeType) -> Self {
Self { source, judge_type }
}

pub fn source(&self) -> &Source {
&self.source
}

pub fn judge_type(&self) -> &JudgeType {
&self.judge_type
}
}

pub enum JudgeType {
SelfTest { input: Bytes },
Submit { cases: TestCases },
}
21 changes: 21 additions & 0 deletions crates/rsjudge-judger/src/judger/request/source.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use bytes::Bytes;
use rsjudge_traits::language::option::LanguageOption;

pub struct Source {
pub(crate) language: LanguageOption,
pub(crate) code: Bytes,
}

impl Source {
pub fn new(language: LanguageOption, code: Bytes) -> Self {
Self { language, code }
}

pub fn language(&self) -> &LanguageOption {
&self.language
}

pub fn code(&self) -> &Bytes {
&self.code
}
}
1 change: 1 addition & 0 deletions crates/rsjudge-judger/src/judger/request/test_cases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct TestCases {}
2 changes: 1 addition & 1 deletion crates/rsjudge-judger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

pub mod comparer;

pub use comparer::{CompareResult, Comparer, DefaultComparer};
pub mod judger;

0 comments on commit ca3cc08

Please sign in to comment.