Skip to content

Commit be86c4d

Browse files
committed
Remove unnecessary funcs and impl Display
1 parent ab47b19 commit be86c4d

File tree

5 files changed

+27
-45
lines changed

5 files changed

+27
-45
lines changed

src/handlers/submission.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -183,33 +183,3 @@ impl std::fmt::Display for SubmitWrong {
183183
)
184184
}
185185
}
186-
187-
impl SubmitWrong {
188-
pub fn display(&self) {
189-
println!("{}", self);
190-
}
191-
}
192-
193-
impl SubmitLimitExceeded {
194-
pub fn display(&self) {
195-
println!("{}", self);
196-
}
197-
}
198-
199-
impl SubmitCorrect {
200-
pub fn display(&self) {
201-
println!("{}", self);
202-
}
203-
}
204-
205-
impl SubmitCompileError {
206-
pub fn display(&self) {
207-
println!("{}", self);
208-
}
209-
}
210-
211-
impl SubmitRuntimeError {
212-
pub fn display(&self) {
213-
println!("{}", self);
214-
}
215-
}

src/handlers/user.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt;
2+
13
use serde::Deserialize;
24

35
#[derive(Debug, Deserialize)]
@@ -9,14 +11,8 @@ pub struct UserMetadata {
911
pub ac_hard: u16,
1012
}
1113

12-
impl UserMetadata {
13-
pub fn display(&self) {
14-
println!("{}", self);
15-
}
16-
}
17-
18-
impl std::fmt::Display for UserMetadata {
19-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14+
impl fmt::Display for UserMetadata {
15+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2016
write!(
2117
f,
2218
"{:18}:{:>15}\n{qs:18}:\n{empty:8}{easy:10}:{ec:>15}\n{empty:8}{med:10}:{mc:>15}\n{empty:8}{hard:10}:{hc:>15}",

src/handlers/utils.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use std::fmt;
2+
13
use super::execution::*;
24
use super::submission::*;
35
use colored::Colorize;
46
use serde::Deserialize;
57

6-
#[derive(Deserialize)]
8+
#[derive(Debug, Deserialize)]
79
#[serde(untagged)]
810
pub enum SubmissionResult {
911
Success(SubmitCorrect),
@@ -42,24 +44,38 @@ pub struct Question {
4244
pub exampleTestcaseList: Vec<String>,
4345
}
4446

45-
#[derive(Deserialize)]
47+
#[derive(Debug, Deserialize)]
4648
pub struct PendingResult {
4749
pub(crate) state: String,
4850
}
4951

50-
#[derive(Deserialize)]
52+
#[derive(Debug, Deserialize)]
5153
pub struct Unknown {}
5254

55+
impl fmt::Display for SubmissionResult {
56+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57+
match self {
58+
SubmissionResult::Success(inner) => write!(f, "{}", inner),
59+
SubmissionResult::CompileError(inner) => write!(f, "{}", inner),
60+
SubmissionResult::RuntimeError(inner) => write!(f, "{}", inner),
61+
SubmissionResult::Wrong(inner) => write!(f, "{}", inner),
62+
SubmissionResult::LimitExceeded(inner) => write!(f, "{}", inner),
63+
SubmissionResult::PendingResult(inner) => write!(f, "{}", inner),
64+
SubmissionResult::Unknown(inner) => write!(f, "Unknown"),
65+
}
66+
}
67+
}
68+
5369
impl PendingResult {
5470
pub fn state(&self) -> PendingState {
5571
match self.state.as_str() {
5672
"PENDING" => PendingState::Pending,
5773
"STARTED" => PendingState::Started,
5874
"SUCCESS" => PendingState::Success,
59-
unknown_state => {
75+
other => {
6076
println!(
6177
"Unknown state : {}\nKindly inform about this to the developer",
62-
unknown_state.cyan().bold()
78+
other.cyan().bold()
6379
);
6480
PendingState::Unknown
6581
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() -> Result<()> {
2727

2828
match cli.command {
2929
Some(Commands::Auth) => match lc.get_metadata() {
30-
Ok(metadata) => metadata.display(),
30+
Ok(metadata) => println!("{}", metadata),
3131
Err(err) => bail!(err),
3232
},
3333
Some(Commands::DailyChallenge) => {

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(crate) fn execute_testcases<P: AsRef<Path>>(
7878

7979
pub(crate) fn submit(lc: &LeetCode<Authorized>, code_file: CodeFile) -> Result<()> {
8080
match lc.submit(&code_file)? {
81-
SubmissionResult::Success(success) => success.display(),
81+
SubmissionResult::Success(success) => println!("{}", success),
8282
SubmissionResult::LimitExceeded(wrong) => {
8383
bail!(wrong)
8484
}

0 commit comments

Comments
 (0)