Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 7, 2024. It is now read-only.

Commit 500894d

Browse files
committed
refactor Leetcode methods to take &self; remove unnecessary .clone()s
1 parent b3937d5 commit 500894d

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

β€Žsrc/cache/mod.rsβ€Ž

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Cache {
6262

6363
async fn get_user_info(&self) -> Result<(String,bool), Error> {
6464
let user = parser::user(
65-
self.clone().0
65+
self.0
6666
.get_user_info().await?
6767
.json().await?
6868
);
@@ -92,7 +92,6 @@ impl Cache {
9292
for i in &self.0.conf.sys.categories.to_owned() {
9393
let json = self
9494
.0
95-
.clone()
9695
.get_category_problems(i)
9796
.await?
9897
.json() // does not require LEETCODE_SESSION
@@ -122,8 +121,7 @@ impl Cache {
122121
/// Get daily problem
123122
pub async fn get_daily_problem_id(&self) -> Result<i32, Error> {
124123
parser::daily(
125-
self.clone()
126-
.0
124+
self.0
127125
.get_question_daily()
128126
.await?
129127
.json() // does not require LEETCODE_SESSION
@@ -167,7 +165,6 @@ impl Cache {
167165
} else {
168166
let json: Value = self
169167
.0
170-
.clone()
171168
.get_question_detail(&target.slug)
172169
.await?
173170
.json()
@@ -205,8 +202,7 @@ impl Cache {
205202
ids = serde_json::from_str(&t.refs)?;
206203
} else {
207204
ids = parser::tags(
208-
self.clone()
209-
.0
205+
self.0
210206
.get_question_ids_by_tag(rslug)
211207
.await?
212208
.json()
@@ -307,7 +303,6 @@ impl Cache {
307303

308304
let json: VerifyResult = self.resp_to_json(
309305
self
310-
.clone()
311306
.0
312307
.verify_result(rid.clone())
313308
.await?
@@ -329,7 +324,6 @@ impl Cache {
329324

330325
let run_res: RunCode = self
331326
.0
332-
.clone()
333327
.run_code(json.clone(), url.clone(), refer.clone())
334328
.await?
335329
.json() // does not require LEETCODE_SESSION (very oddly)

β€Žsrc/plugins/leetcode.rsβ€Ž

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct LeetCode {
2121

2222
macro_rules! make_req {
2323
($self:ident, $url:expr) => {
24-
Req::new($self.default_headers, function_name!(), $url)
24+
Req::new($self.default_headers.to_owned(), function_name!(), $url)
2525
}
2626
}
2727

@@ -74,7 +74,7 @@ impl LeetCode {
7474

7575
/// Get category problems
7676
#[named]
77-
pub async fn get_category_problems(self, category: &str) -> Result<Response, Error> {
77+
pub async fn get_category_problems(&self, category: &str) -> Result<Response, Error> {
7878
trace!("Requesting {} problems...", &category);
7979
let url = &self
8080
.conf
@@ -89,7 +89,7 @@ impl LeetCode {
8989
}
9090

9191
#[named]
92-
pub async fn get_question_ids_by_tag(self, slug: &str) -> Result<Response, Error> {
92+
pub async fn get_question_ids_by_tag(&self, slug: &str) -> Result<Response, Error> {
9393
trace!("Requesting {} ref problems...", &slug);
9494
let url = &self.conf.sys.urls.get("graphql").ok_or(Error::NoneError)?;
9595
let mut json: Json = HashMap::new();
@@ -115,7 +115,7 @@ impl LeetCode {
115115
}
116116

117117
#[named]
118-
pub async fn get_user_info(self) -> Result<Response, Error> {
118+
pub async fn get_user_info(&self) -> Result<Response, Error> {
119119
let url = &self.conf.sys.urls.get("graphql").ok_or(Error::NoneError)?;
120120
let mut json: Json = HashMap::new();
121121
json.insert("operationName", "a".to_string());
@@ -138,7 +138,7 @@ impl LeetCode {
138138

139139
/// Get daily problem
140140
#[named]
141-
pub async fn get_question_daily(self) -> Result<Response, Error> {
141+
pub async fn get_question_daily(&self) -> Result<Response, Error> {
142142
let url = &self.conf.sys.urls.get("graphql").ok_or(Error::NoneError)?;
143143
let mut json: Json = HashMap::new();
144144
json.insert("operationName", "daily".to_string());
@@ -162,7 +162,7 @@ impl LeetCode {
162162

163163
/// Get specific problem detail
164164
#[named]
165-
pub async fn get_question_detail(self, slug: &str) -> Result<Response, Error> {
165+
pub async fn get_question_detail(&self, slug: &str) -> Result<Response, Error> {
166166
trace!("Requesting {} detail...", &slug);
167167
let refer = self.conf.sys.urls.get("problems").ok_or(Error::NoneError)?.replace("$slug", slug);
168168
let url = &self.conf.sys.urls.get("graphql").ok_or(Error::NoneError)?;
@@ -200,7 +200,7 @@ impl LeetCode {
200200

201201
/// Send code to judge
202202
#[named]
203-
pub async fn run_code(self, j: Json, url: String, refer: String) -> Result<Response, Error> {
203+
pub async fn run_code(&self, j: Json, url: String, refer: String) -> Result<Response, Error> {
204204
let mut req = make_req!(self, url);
205205
req.mode = Mode::Post(j);
206206
req.refer = Some(refer);
@@ -211,7 +211,7 @@ impl LeetCode {
211211

212212
/// Get the result of submission / testing
213213
#[named]
214-
pub async fn verify_result(self, id: String) -> Result<Response, Error> {
214+
pub async fn verify_result(&self, id: String) -> Result<Response, Error> {
215215
let url = self.conf.sys.urls.get("verify").ok_or(Error::NoneError)?.replace("$id", &id);
216216
make_req!(self, url)
217217
.send(&self.client)

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /