forked from clearloop/leetcode-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.rs
More file actions
83 lines (76 loc) · 2.54 KB
/
code.rs
File metadata and controls
83 lines (76 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Code in config
use serde::{Deserialize, Serialize};
const PICK_DEFAULT: &str = "${fid}.${slug}";
fn default_pick() -> String {
PICK_DEFAULT.into()
}
const SUBMISSION_DEFAULT: &str = "${fid}.${slug}.${sid}.${ac}";
fn default_submission() -> String {
SUBMISSION_DEFAULT.into()
}
fn is_default_pick(t: &String) -> bool {
t == PICK_DEFAULT
}
fn is_default_submission(t: &String) -> bool {
t == SUBMISSION_DEFAULT
}
fn is_default_string(t: &String) -> bool {
t.is_empty()
}
fn is_default_bool(t: &bool) -> bool {
!t
}
/// Code config
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Code {
#[serde(default)]
pub editor: String,
#[serde(rename(serialize = "editor-args"), alias = "editor-args", default)]
pub editor_args: Option<Vec<String>>,
#[serde(rename(serialize = "editor-envs"), alias = "editor-envs", default)]
pub editor_envs: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "is_default_bool")]
pub edit_code_marker: bool,
#[serde(default, skip_serializing_if = "is_default_string")]
pub start_marker: String,
#[serde(default, skip_serializing_if = "is_default_string")]
pub end_marker: String,
#[serde(rename(serialize = "inject_before"), alias = "inject_before", default)]
pub inject_before: Option<Vec<String>>,
#[serde(rename(serialize = "inject_after"), alias = "inject_after", default)]
pub inject_after: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "is_default_bool")]
pub comment_problem_desc: bool,
#[serde(default, skip_serializing_if = "is_default_string")]
pub comment_leading: String,
#[serde(default, skip_serializing_if = "is_default_bool")]
pub test: bool,
pub lang: String,
#[serde(default = "default_pick", skip_serializing_if = "is_default_pick")]
pub pick: String,
#[serde(
default = "default_submission",
skip_serializing_if = "is_default_submission"
)]
pub submission: String,
}
impl Default for Code {
fn default() -> Self {
Self {
editor: "vim".into(),
editor_args: None,
editor_envs: None,
edit_code_marker: false,
start_marker: "".into(),
end_marker: "".into(),
inject_before: None,
inject_after: None,
comment_problem_desc: false,
comment_leading: "".into(),
test: true,
lang: "rust".into(),
pick: "${fid}.${slug}".into(),
submission: "${fid}.${slug}.${sid}.${ac}".into(),
}
}
}