diff --git a/Cargo.lock b/Cargo.lock index 13f0e15..c3e5cc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -251,7 +251,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -286,7 +286,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -425,18 +425,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.4" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" dependencies = [ "anstream", "anstyle", @@ -446,9 +446,9 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.2" +version = "4.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79504325bf38b10165b02e89b4347300f855f273c4cb30c4a3209e6583275e" +checksum = "1d598e88f6874d4b888ed40c71efbcbf4076f1dfbae128a08a8c9e45f710605d" dependencies = [ "clap", ] @@ -557,7 +557,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" dependencies = [ "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -581,7 +581,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -592,7 +592,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -628,9 +628,9 @@ dependencies = [ [[package]] name = "diesel" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35b696af9ff4c0d2a507db2c5faafa8aa0205e297e5f11e203a24226d5355e7a" +checksum = "62d6dcd069e7b5fe49a302411f759d4cf1cf2c27fe798ef46fb8baefc053dd2b" dependencies = [ "diesel_derives", "libsqlite3-sys", @@ -647,7 +647,7 @@ dependencies = [ "dsl_auto_type", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -656,7 +656,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" dependencies = [ - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -699,10 +699,10 @@ checksum = "ab32c18ea6760d951659768a3e35ea72fc1ba0916d665a88dfe048b2a41e543f" dependencies = [ "darling", "either", - "heck 0.5.0", + "heck", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -759,7 +759,7 @@ checksum = "f95e2801cd355d4a1a3e3953ce6ee5ae9603a5c833455343a8bfe3f44d418246" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -961,7 +961,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -1063,12 +1063,6 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -1185,6 +1179,23 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-rustls" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + [[package]] name = "hyper-tls" version = "0.6.0" @@ -1403,9 +1414,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "mac" @@ -1655,7 +1666,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -1786,7 +1797,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -1824,7 +1835,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -1922,24 +1933,24 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" +checksum = "1962a33ed2a201c637fc14a4e0fd4e06e6edfdeee6a5fede0dab55507ad74cf7" dependencies = [ "cfg-if", "indoc", "libc", "memoffset 0.9.0", - "parking_lot", + "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -1949,9 +1960,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" +checksum = "ab7164b2202753bd33afc7f90a10355a719aa973d1f94502c50d06f3488bc420" dependencies = [ "once_cell", "target-lexicon", @@ -1959,9 +1970,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" +checksum = "c6424906ca49013c0829c5c1ed405e20e2da2dc78b82d198564880a704e6a7b7" dependencies = [ "libc", "pyo3-build-config", @@ -1969,27 +1980,27 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" +checksum = "82b2f19e153122d64afd8ce7aaa72f06a00f52e34e1d1e74b6d71baea396460a" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] name = "pyo3-macros-backend" -version = "0.21.2" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" +checksum = "dd698c04cac17cf0fe63d47790ab311b8b25542f5cb976b65c374035c50f1eef" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -2053,9 +2064,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.4" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", @@ -2082,9 +2093,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" +checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" dependencies = [ "async-compression", "base64", @@ -2097,6 +2108,7 @@ dependencies = [ "http-body", "http-body-util", "hyper", + "hyper-rustls", "hyper-tls", "hyper-util", "ipnet", @@ -2124,6 +2136,21 @@ dependencies = [ "winreg", ] +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -2157,6 +2184,19 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.23.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebbbdb961df0ad3f2652da8f3fdc4b36122f568f968f45ad3316f26c025c677b" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + [[package]] name = "rustls-pemfile" version = "2.1.2" @@ -2173,6 +2213,17 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "beb461507cee2c2ff151784c52762cf4d9ff6a61f3e80968600ed24fa837fa54" +[[package]] +name = "rustls-webpki" +version = "0.102.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3bce581c0dd41bce533ce695a1437fa16a7ab5ac3ccfa99fe1a620a7885eabf" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "ryu" version = "1.0.16" @@ -2288,14 +2339,14 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "itoa", "ryu", @@ -2310,7 +2361,7 @@ checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -2415,6 +2466,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -2484,9 +2541,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -2495,9 +2552,9 @@ dependencies = [ [[package]] name = "sync_wrapper" -version = "0.1.2" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" [[package]] name = "system-configuration" @@ -2522,9 +2579,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.12" +version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" +checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" [[package]] name = "tempfile" @@ -2567,7 +2624,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -2641,7 +2698,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -2654,6 +2711,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.10" @@ -2670,14 +2738,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.13" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4e43f8cc456c9704c851ae29c67e17ef65d2c30017c17a9765b89c382dc8bba" +checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.13", + "toml_edit 0.22.14", ] [[package]] @@ -2702,9 +2770,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.13" +version = "0.22.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c127785850e8c20836d49732ae6abfa47616e60bf9d9f57c43c250361a9db96c" +checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" dependencies = [ "indexmap", "serde", @@ -2761,7 +2829,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -2829,6 +2897,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.0" @@ -2906,7 +2980,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", "wasm-bindgen-shared", ] @@ -2940,7 +3014,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3236,9 +3310,15 @@ checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + [[package]] name = "zvariant" version = "3.15.0" diff --git a/Cargo.toml b/Cargo.toml index fee85e0..d9250d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ path = "src/bin/lc.rs" [package] name = "leetcode-cli" -version = "0.4.3" +version = "0.4.4" authors = ["clearloop "] edition = "2021" description = "Leetcode command-line interface in rust." @@ -18,30 +18,30 @@ readme = './README.md' [dependencies] async-trait = "0.1.80" tokio = { version = "1.38.0", features = ["full"] } -clap = { version = "4.5.4", features = ["cargo"] } +clap = { version = "4.5.8", features = ["cargo"] } colored = "2.1.0" dirs = "5.0.1" env_logger = "0.11.3" keyring = "2.3.3" -log = "0.4.21" +log = "0.4.22" openssl = "0.10.64" -pyo3 = { version = "0.21.2", optional = true } +pyo3 = { version = "0.22.0", optional = true } rand = "0.8.5" serde = { version = "1.0.203", features = ["derive"] } -serde_json = "1.0.117" -toml = "0.8.13" -regex = "1.10.4" +serde_json = "1.0.120" +toml = "0.8.14" +regex = "1.10.5" scraper = "0.19.0" anyhow = "1.0.86" -clap_complete = "4.5.2" +clap_complete = "4.5.7" thiserror = "1.0.61" [dependencies.diesel] -version = "2.2.0" +version = "2.2.1" features = ["sqlite"] [dependencies.reqwest] -version = "0.12.4" +version = "0.12.5" features = ["gzip", "json"] [features] diff --git a/src/cache/mod.rs b/src/cache/mod.rs index f5efd1f..3250bf6 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -23,16 +23,13 @@ pub fn conn(p: String) -> SqliteConnection { /// Condition submit or test #[derive(Clone, Debug)] +#[derive(Default)] pub enum Run { Test, + #[default] Submit, } -impl Default for Run { - fn default() -> Self { - Run::Submit - } -} /// Requests if data not download #[derive(Clone)] diff --git a/src/cache/parser.rs b/src/cache/parser.rs index ec01301..0474c1f 100644 --- a/src/cache/parser.rs +++ b/src/cache/parser.rs @@ -15,12 +15,12 @@ pub fn problem(problems: &mut Vec, v: Value) -> Option<()> { // Handle on leetcode-com Some(s) => s as i32, // Handle on leetcode-cn - None => fid_obj.as_str()?.split(" ").last()?.parse::().ok()?, + None => fid_obj.as_str()?.split(' ').last()?.parse::().ok()?, }; problems.push(Problem { category: v.get("category_slug")?.as_str()?.to_string(), - fid: fid, + fid, id: stat.get("question_id")?.as_i64()? as i32, level: p.get("difficulty")?.as_object()?.get("level")?.as_i64()? as i32, locked: p.get("paid_only")?.as_bool()?, @@ -102,7 +102,7 @@ pub fn daily(v: Value) -> Option { // Handle on leetcode-com Some(v) => v, // Handle on leetcode-cn - None => v_obj.get("todayRecord")?.as_array()?.get(0)?, + None => v_obj.get("todayRecord")?.as_array()?.first()?, } .as_object()? .get("question")? diff --git a/src/cmds/list.rs b/src/cmds/list.rs index 9c46df9..ae6df47 100644 --- a/src/cmds/list.rs +++ b/src/cmds/list.rs @@ -184,7 +184,6 @@ impl Command for ListCommand { .get_many::("range") .ok_or(Error::NoneError)? .copied() - .into_iter() .collect(); ps.retain(|x| num_range[0] <= x.fid && x.fid <= num_range[1]); } diff --git a/src/cmds/pick.rs b/src/cmds/pick.rs index ae39f48..3597d5d 100644 --- a/src/cmds/pick.rs +++ b/src/cmds/pick.rs @@ -139,11 +139,8 @@ impl Command for PickCommand { let fid = match m.contains_id("name") { // check for name specified, or closest name true => { - match m.get_one::("name").map(|name| name) { - Some(quesname) => match closest_named_problem(&problems, quesname) { - Some(p) => p, - None => 1, - }, + match m.get_one::("name") { + Some(quesname) => closest_named_problem(&problems, quesname).unwrap_or(1), None => { // Pick random without specify id let problem = &problems[rand::thread_rng().gen_range(0..problems.len())]; @@ -190,7 +187,7 @@ fn closest_named_problem(problems: &Vec, lookup_name: &str) -> Option = vec![0; (max_name_size + 1) * (lookup_name.len() + 1)]; // this is guaranteed because of the earlier max None propegation - assert!(problems.len() > 0); + assert!(!problems.is_empty()); let mut max_score = 0; let mut current_problem = &problems[0]; for problem in problems { @@ -204,7 +201,7 @@ fn closest_named_problem(problems: &Vec, lookup_name: &str) -> Option max_score { max_score = this_score; - current_problem = &problem; + current_problem = problem; } } @@ -213,7 +210,7 @@ fn closest_named_problem(problems: &Vec, lookup_name: &str) -> Option, text1: &str, text2: &str) -> usize { +fn longest_common_subsequence(table: &mut [usize], text1: &str, text2: &str) -> usize { assert!(table.len() >= (text1.len() + 1) * (text2.len() + 1)); let height: usize = text1.len() + 1; let width: usize = text2.len() + 1; diff --git a/src/cmds/stat.rs b/src/cmds/stat.rs index 913064a..4b463da 100644 --- a/src/cmds/stat.rs +++ b/src/cmds/stat.rs @@ -81,7 +81,7 @@ impl Command for StatCommand { ); // lines - for (i, l) in vec![(easy, easy_ac), (medium, medium_ac), (hard, hard_ac)] + for (i, l) in [(easy, easy_ac), (medium, medium_ac), (hard, hard_ac)] .iter() .enumerate() { diff --git a/src/config/cookies.rs b/src/config/cookies.rs index c4ca62e..6c5f5c6 100644 --- a/src/config/cookies.rs +++ b/src/config/cookies.rs @@ -1,7 +1,9 @@ //! Cookies in config -use std::str::FromStr; - use serde::{Deserialize, Serialize}; +use std::{ + fmt::{self, Display}, + str::FromStr, +}; #[derive(Clone, Debug, Deserialize, Serialize)] pub enum LeetcodeSite { @@ -22,12 +24,14 @@ impl FromStr for LeetcodeSite { } } -impl ToString for LeetcodeSite { - fn to_string(&self) -> String { - match self { - LeetcodeSite::LeetcodeCom => "leetcode.com".to_string(), - LeetcodeSite::LeetcodeCn => "leetcode.cn".to_string(), - } +impl Display for LeetcodeSite { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match self { + LeetcodeSite::LeetcodeCom => "leetcode.com", + LeetcodeSite::LeetcodeCn => "leetcode.cn", + }; + + write!(f, "{s}") } } @@ -49,8 +53,12 @@ impl Default for Cookies { } } -impl std::string::ToString for Cookies { - fn to_string(&self) -> String { - format!("LEETCODE_SESSION={};csrftoken={};", self.session, self.csrf) +impl Display for Cookies { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "LEETCODE_SESSION={};csrftoken={};", + self.session, self.csrf + ) } } diff --git a/src/config/storage.rs b/src/config/storage.rs index 5d6fda6..0395b1f 100644 --- a/src/config/storage.rs +++ b/src/config/storage.rs @@ -65,7 +65,7 @@ impl Storage { self.scripts = Some("scripts".into()); } - let p = PathBuf::from(root).join(&self.scripts.ok_or(Error::NoneError)?); + let p = PathBuf::from(root).join(self.scripts.ok_or(Error::NoneError)?); if !PathBuf::from(&p).exists() { std::fs::create_dir(&p)? } diff --git a/src/helper.rs b/src/helper.rs index 7aa533a..321828c 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -87,7 +87,8 @@ mod filter { ids.iter().for_each(|x| { map.insert(x.to_string(), true).unwrap_or_default(); }); - ps.retain(|x| map.get(&x.id.to_string()).is_some()); + + ps.retain(|x| map.contains_key(&x.id.to_string())); Ok(()) } } diff --git a/src/plugins/chrome.rs b/src/plugins/chrome.rs index 8f6b0f4..0825300 100644 --- a/src/plugins/chrome.rs +++ b/src/plugins/chrome.rs @@ -3,7 +3,7 @@ use anyhow::anyhow; use diesel::prelude::*; use keyring::Entry; use openssl::{hash, pkcs5, symm}; -use std::collections::HashMap; +use std::{collections::HashMap, fmt::Display}; /// LeetCode Cookies Schema mod schema { @@ -34,9 +34,13 @@ pub struct Ident { session: String, } -impl std::string::ToString for Ident { - fn to_string(&self) -> String { - format!("LEETCODE_SESSION={};csrftoken={};", self.session, self.csrf) +impl Display for Ident { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "LEETCODE_SESSION={};csrftoken={};", + self.session, self.csrf + ) } } @@ -64,7 +68,7 @@ pub fn cookies() -> Result { debug!("Chrome Cookies path is {:?}", &p); let mut conn = cache::conn(p.to_string_lossy().to_string()); let res = cookies - .filter(host_key.like(format!("#{}", ccfg.site.to_string()))) + .filter(host_key.like(format!("#{}", ccfg.site))) .load::(&mut conn) .expect("Loading cookies from google chrome failed."); diff --git a/src/plugins/leetcode.rs b/src/plugins/leetcode.rs index caf1cf7..ec8a924 100644 --- a/src/plugins/leetcode.rs +++ b/src/plugins/leetcode.rs @@ -86,15 +86,13 @@ impl LeetCode { json.insert("variables", r#"{"slug": "$slug"}"#.replace("$slug", slug)); json.insert( "query", - vec![ - "query getTopicTag($slug: String!) {", + ["query getTopicTag($slug: String!) {", " topicTag(slug: $slug) {", " questions {", " questionId", " }", " }", - "}", - ] + "}"] .join("\n"), ); @@ -151,15 +149,13 @@ impl LeetCode { json.insert("operationName", "daily".to_string()); json.insert( "query", - vec![ - "query daily {", + ["query daily {", " activeDailyCodingChallengeQuestion {", " question {", " questionFrontendId", " }", " }", - "}", - ] + "}"] .join("\n"), ); } @@ -167,15 +163,13 @@ impl LeetCode { json.insert("operationName", "questionOfToday".to_string()); json.insert( "query", - vec![ - "query questionOfToday {", + ["query questionOfToday {", " todayRecord {", " question {", " questionFrontendId", " }", " }", - "}", - ] + "}"] .join("\n"), ); } @@ -201,8 +195,7 @@ impl LeetCode { let mut json: Json = HashMap::new(); json.insert( "query", - vec![ - "query getQuestionDetail($titleSlug: String!) {", + ["query getQuestionDetail($titleSlug: String!) {", " question(titleSlug: $titleSlug) {", " content", " stats", @@ -213,8 +206,7 @@ impl LeetCode { " metaData", " translatedContent", " }", - "}", - ] + "}"] .join("\n"), ); @@ -232,7 +224,7 @@ impl LeetCode { json: Some(json), mode: Mode::Post, name: "get_problem_detail", - url: self.conf.sys.urls.graphql.into(), + url: self.conf.sys.urls.graphql, } .send(&self.client) .await diff --git a/src/pym.rs b/src/pym.rs index 3df3571..31b0dc1 100644 --- a/src/pym.rs +++ b/src/pym.rs @@ -16,7 +16,7 @@ pub fn exec(module: &str) -> Result> { // pygil Python::with_gil(|py| { - let pym = PyModule::from_code(py, &script, "plan.py", "plan")?; + let pym = PyModule::from_code_bound(py, &script, "plan.py", "plan")?; pym.getattr("plan")?.call1((sps, stags))?.extract() }) .map_err(Into::into)