Skip to content

Commit 5318005

Browse files
committed
chore(clippy): make clippy happy
1 parent f58dae1 commit 5318005

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

src/cmds/pick.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn closest_named_problem(problems: &Vec<Problem>, lookup_name: &str) -> Option<i
210210

211211
// Longest commong subsequence DP approach O(nm) space and time. Table must be at least
212212
// (text1.len() + 1) * (text2.len() + 1) length or greater and is mutated every call
213-
fn longest_common_subsequence(table: &mut Vec<usize>, text1: &str, text2: &str) -> usize {
213+
fn longest_common_subsequence(table: &mut [usize], text1: &str, text2: &str) -> usize {
214214
assert!(table.len() >= (text1.len() + 1) * (text2.len() + 1));
215215
let height: usize = text1.len() + 1;
216216
let width: usize = text2.len() + 1;

src/config/cookies.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Cookies in config
2-
use std::str::FromStr;
3-
42
use serde::{Deserialize, Serialize};
3+
use std::{
4+
fmt::{self, Display},
5+
str::FromStr,
6+
};
57

68
#[derive(Clone, Debug, Deserialize, Serialize)]
79
pub enum LeetcodeSite {
@@ -22,12 +24,14 @@ impl FromStr for LeetcodeSite {
2224
}
2325
}
2426

25-
impl ToString for LeetcodeSite {
26-
fn to_string(&self) -> String {
27-
match self {
28-
LeetcodeSite::LeetcodeCom => "leetcode.com".to_string(),
29-
LeetcodeSite::LeetcodeCn => "leetcode.cn".to_string(),
30-
}
27+
impl Display for LeetcodeSite {
28+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29+
let s = match self {
30+
LeetcodeSite::LeetcodeCom => "leetcode.com",
31+
LeetcodeSite::LeetcodeCn => "leetcode.cn",
32+
};
33+
34+
write!(f, "{s}")
3135
}
3236
}
3337

@@ -49,8 +53,12 @@ impl Default for Cookies {
4953
}
5054
}
5155

52-
impl std::string::ToString for Cookies {
53-
fn to_string(&self) -> String {
54-
format!("LEETCODE_SESSION={};csrftoken={};", self.session, self.csrf)
56+
impl Display for Cookies {
57+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58+
write!(
59+
f,
60+
"LEETCODE_SESSION={};csrftoken={};",
61+
self.session, self.csrf
62+
)
5563
}
5664
}

src/helper.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ mod filter {
8787
ids.iter().for_each(|x| {
8888
map.insert(x.to_string(), true).unwrap_or_default();
8989
});
90-
ps.retain(|x| map.get(&x.id.to_string()).is_some());
90+
91+
ps.retain(|x| map.contains_key(&x.id.to_string()));
9192
Ok(())
9293
}
9394
}

src/plugins/chrome.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use anyhow::anyhow;
33
use diesel::prelude::*;
44
use keyring::Entry;
55
use openssl::{hash, pkcs5, symm};
6-
use std::collections::HashMap;
6+
use std::{collections::HashMap, fmt::Display};
77

88
/// LeetCode Cookies Schema
99
mod schema {
@@ -34,9 +34,13 @@ pub struct Ident {
3434
session: String,
3535
}
3636

37-
impl std::string::ToString for Ident {
38-
fn to_string(&self) -> String {
39-
format!("LEETCODE_SESSION={};csrftoken={};", self.session, self.csrf)
37+
impl Display for Ident {
38+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39+
write!(
40+
f,
41+
"LEETCODE_SESSION={};csrftoken={};",
42+
self.session, self.csrf
43+
)
4044
}
4145
}
4246

@@ -64,7 +68,7 @@ pub fn cookies() -> Result<Ident> {
6468
debug!("Chrome Cookies path is {:?}", &p);
6569
let mut conn = cache::conn(p.to_string_lossy().to_string());
6670
let res = cookies
67-
.filter(host_key.like(format!("#{}", ccfg.site.to_string())))
71+
.filter(host_key.like(format!("#{}", ccfg.site)))
6872
.load::<Cookies>(&mut conn)
6973
.expect("Loading cookies from google chrome failed.");
7074

src/pym.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn exec(module: &str) -> Result<Vec<String>> {
1616

1717
// pygil
1818
Python::with_gil(|py| {
19-
let pym = PyModule::from_code(py, &script, "plan.py", "plan")?;
19+
let pym = PyModule::from_code_bound(py, &script, "plan.py", "plan")?;
2020
pym.getattr("plan")?.call1((sps, stags))?.extract()
2121
})
2222
.map_err(Into::into)

0 commit comments

Comments
 (0)