diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-01-14 10:06:22 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-01-14 10:13:04 +0100 |
| commit | 8de88b5c7c41bc16a8f6979b69bbd94b7fb9b5cd (patch) | |
| tree | dff46c9dd3cd1f5cee05b7b397e134fec8f5c4cc | |
| parent | d72440ead7be71bd025a6b893dcd546d6d5a43bb (diff) | |
| download | mihi-8de88b5c7c41bc16a8f6979b69bbd94b7fb9b5cd.tar.gz mihi-8de88b5c7c41bc16a8f6979b69bbd94b7fb9b5cd.zip | |
Migrate from usize to isize for integers in models
SQLite3, like many other DBs (e.g. PostgreSQL), assumes by default an
i64::MAX value. Hence, while in the application we are talking mainly in
unsigned terms (which is what makes sense here), this is not realistic
to what ends up happening on the DB side.
Up until now this just worked behind the scenes because rustqlite did
the heavy lifting via default trait implementations of usize which
handled this translation for us. This default implementation for usize
was dropped in 0.38.0 (see [1]). Even if it can be enabled back via the
"fallible_uint" feature, it's more fair to stick to isize, as it's not
much of a problem on our side, and it's more transparent in regards to
what happens in the end in the DB.
Last but not least, this commit also upgrades rustqlite to the latest
0.38.0, with the rest of the dependency tree.
[1] https://github.com/rusqlite/rusqlite/issues/1722)
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
| -rw-r--r-- | Cargo.lock | 182 | ||||
| -rw-r--r-- | crates/cli/src/run.rs | 2 | ||||
| -rw-r--r-- | crates/cli/src/words.rs | 8 | ||||
| -rw-r--r-- | lib/mihi/Cargo.toml | 2 | ||||
| -rw-r--r-- | lib/mihi/src/lib.rs | 89 |
5 files changed, 196 insertions, 87 deletions
@@ -15,6 +15,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] +name = "bumpalo" +version = "3.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" + +[[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -22,9 +28,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.2.43" +version = "1.2.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "739eb0f94557554b3ca9a86d2d37bebd49c5e6d0c1d2bda35ba5bdac830befc2" +checksum = "cd4932aefd12402b36c60956a4fe0035421f544799057659ff86f923657aada3" dependencies = [ "find-msvc-tools", "shlex", @@ -108,15 +114,15 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "find-msvc-tools" -version = "0.1.4" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" +checksum = "f449e6c6c08c865631d4890cfacf252b3d396c9bcc83adb6623cdb02a8336c41" [[package]] name = "foldhash" -version = "0.1.5" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" [[package]] name = "fuzzy-matcher" @@ -150,18 +156,18 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.5" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ "foldhash", ] [[package]] name = "hashlink" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" +checksum = "ea0b22561a9c04a7cb1a302c013e0259cd3b4bb619f145b32f72b8b4bcbed230" dependencies = [ "hashbrown", ] @@ -186,21 +192,31 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "js-sys" +version = "0.3.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" +dependencies = [ + "once_cell", + "wasm-bindgen", +] [[package]] name = "libc" -version = "0.2.177" +version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" [[package]] name = "libsqlite3-sys" -version = "0.33.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "947e6816f7825b2b45027c2c32e7085da9934defa535de4a6a46b10a4d5257fa" +checksum = "95b4103cffefa72eb8428cb6b47d6627161e51c2739fc5e3b734584157bc642a" dependencies = [ "cc", "pkg-config", @@ -224,9 +240,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.28" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "memchr" @@ -301,18 +317,18 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "proc-macro2" -version = "1.0.103" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.41" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" dependencies = [ "proc-macro2", ] @@ -334,9 +350,9 @@ dependencies = [ [[package]] name = "rusqlite" -version = "0.35.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a22715a5d6deef63c637207afbe68d0c72c3f8d0022d7cf9714c442d6157606b" +checksum = "f1c93dd1c9683b438c392c492109cb702b8090b2bfc8fed6f6e4eb4523f17af3" dependencies = [ "bitflags 2.10.0", "fallible-iterator", @@ -344,13 +360,14 @@ dependencies = [ "hashlink", "libsqlite3-sys", "smallvec", + "sqlite-wasm-rs", ] [[package]] name = "rustix" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" +checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" dependencies = [ "bitflags 2.10.0", "errno", @@ -360,10 +377,10 @@ dependencies = [ ] [[package]] -name = "ryu" -version = "1.0.20" +name = "rustversion" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "scopeguard" @@ -403,15 +420,15 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.145" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", "memchr", - "ryu", "serde", "serde_core", + "zmij", ] [[package]] @@ -443,10 +460,11 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.6" +version = "1.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" dependencies = [ + "errno", "libc", ] @@ -457,10 +475,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] +name = "sqlite-wasm-rs" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05e98301bf8b0540c7de45ecd760539b9c62f5772aed172f08efba597c11cd5d" +dependencies = [ + "cc", + "hashbrown", + "js-sys", + "thiserror", + "wasm-bindgen", +] + +[[package]] name = "syn" -version = "2.0.108" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -469,9 +500,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.23.0" +version = "3.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" +checksum = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c" dependencies = [ "fastrand", "getrandom", @@ -481,6 +512,26 @@ dependencies = [ ] [[package]] +name = "thiserror" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "thread_local" version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -491,9 +542,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "unicode-segmentation" @@ -529,6 +580,51 @@ dependencies = [ ] [[package]] +name = "wasm-bindgen" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" +dependencies = [ + "unicode-ident", +] + +[[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -636,3 +732,9 @@ name = "wit-bindgen" version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + +[[package]] +name = "zmij" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd8f3f50b848df28f887acb68e41201b5aea6bc8a8dacc00fb40635ff9a72fea" diff --git a/crates/cli/src/run.rs b/crates/cli/src/run.rs index 5d121d2..0084a6c 100644 --- a/crates/cli/src/run.rs +++ b/crates/cli/src/run.rs @@ -50,7 +50,7 @@ fn run_words(words: Vec<Word>, locale: &Locale) -> i32 { let found = !answer.is_empty() && tr.split(',').any(|tr| tr.trim().contains(answer)); if found { - if word.steps == MAX_STEPS - 1 { + if word.steps as usize == MAX_STEPS - 1 { let _ = update_success(&word, word.succeeded + 1, 0); } else { let _ = update_success(&word, word.succeeded, word.steps + 1); diff --git a/crates/cli/src/words.rs b/crates/cli/src/words.rs index 60609a9..9ed16d3 100644 --- a/crates/cli/src/words.rs +++ b/crates/cli/src/words.rs @@ -221,7 +221,7 @@ fn ask_for_word_based_on(enunciated: String, word: Word) -> Result<Word, String> Category::Determiner, ]; let Ok(category) = Select::new("Category:", categories) - .with_starting_cursor(word.category as usize) + .with_starting_cursor((word.category as isize).try_into().unwrap()) .prompt() else { return Err("abort!".to_string()); @@ -237,7 +237,7 @@ fn ask_for_word_based_on(enunciated: String, word: Word) -> Result<Word, String> let gender = match category { Category::Noun => { match Select::new("Gender:", genders) - .with_starting_cursor(word.gender as usize) + .with_starting_cursor((word.gender as isize).try_into().unwrap()) .prompt() { Ok(selection) => selection, @@ -255,7 +255,7 @@ fn ask_for_word_based_on(enunciated: String, word: Word) -> Result<Word, String> else { return Err("abort!".to_string()); }; - let Ok(inflection_id) = inflection.parse::<usize>() else { + let Ok(inflection_id) = inflection.parse::<isize>() else { return Err(format!("bad value for inflection ID '{inflection}'")); }; Some(inflection_id) @@ -305,7 +305,7 @@ fn ask_for_word_based_on(enunciated: String, word: Word) -> Result<Word, String> else { return Err("abort!".to_string()); }; - let Ok(weight) = raw_weight.parse::<usize>() else { + let Ok(weight) = raw_weight.parse::<isize>() else { return Err(format!( "bad value for inflection ID '{}'", inflection_id.unwrap_or(0) diff --git a/lib/mihi/Cargo.toml b/lib/mihi/Cargo.toml index 4b973d6..15ed1fb 100644 --- a/lib/mihi/Cargo.toml +++ b/lib/mihi/Cargo.toml @@ -8,6 +8,6 @@ edition.workspace = true license.workspace = true [dependencies] -rusqlite = { version = "0.35.0", features = ["bundled"] } +rusqlite = { version = "0.38.0", features = ["bundled"] } serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/lib/mihi/src/lib.rs b/lib/mihi/src/lib.rs index 5c15d8c..fc73189 100644 --- a/lib/mihi/src/lib.rs +++ b/lib/mihi/src/lib.rs @@ -40,10 +40,10 @@ impl std::fmt::Display for Category { } } -impl TryFrom<usize> for Category { +impl TryFrom<isize> for Category { type Error = &'static str; - fn try_from(value: usize) -> Result<Self, Self::Error> { + fn try_from(value: isize) -> Result<Self, Self::Error> { match value { 0 => Ok(Self::Unknown), 1 => Ok(Self::Noun), @@ -83,10 +83,10 @@ impl Gender { } } -impl TryFrom<usize> for Gender { +impl TryFrom<isize> for Gender { type Error = &'static str; - fn try_from(value: usize) -> Result<Self, Self::Error> { + fn try_from(value: isize) -> Result<Self, Self::Error> { match value { 0 => Ok(Self::Masculine), 1 => Ok(Self::Feminine), @@ -117,10 +117,10 @@ pub enum Language { Latin, } -impl TryFrom<usize> for Language { +impl TryFrom<isize> for Language { type Error = &'static str; - fn try_from(value: usize) -> Result<Self, Self::Error> { + fn try_from(value: isize) -> Result<Self, Self::Error> { match value { 0 => Ok(Self::Unknown), 1 => Ok(Self::Latin), @@ -206,8 +206,8 @@ pub struct Word { pub enunciated: String, pub particle: String, pub language: Language, - pub declension_id: Option<usize>, - pub conjugation_id: Option<usize>, + pub declension_id: Option<isize>, + pub conjugation_id: Option<isize>, pub kind: String, pub category: Category, pub regular: bool, @@ -216,17 +216,17 @@ pub struct Word { pub suffix: Option<String>, pub translation: Value, pub flags: Value, - pub succeeded: usize, - pub steps: usize, - pub weight: usize, + pub succeeded: isize, + pub steps: isize, + pub weight: isize, } impl Word { pub fn from( particle: String, category: Category, - declension_id: Option<usize>, - conjugation_id: Option<usize>, + declension_id: Option<isize>, + conjugation_id: Option<isize>, gender: Gender, kind: String, ) -> Word { @@ -251,7 +251,7 @@ impl Word { } } - pub fn inflection_id(&self) -> Option<usize> { + pub fn inflection_id(&self) -> Option<isize> { if matches!(self.category, Category::Verb) { return Some(self.conjugation_id.unwrap()); } @@ -341,7 +341,7 @@ pub fn create_word(word: Word) -> Result<(), String> { match word.category { Category::Noun => match word.declension_id { Some(id @ 1..7) => { - if !DECLENSIONS_WITH_KINDS[id - 1].contains(&word.kind.as_str()) { + if !DECLENSIONS_WITH_KINDS[id as usize - 1].contains(&word.kind.as_str()) { return Err(format!("bad kind for declension '{id}'")); } } @@ -354,7 +354,7 @@ pub fn create_word(word: Word) -> Result<(), String> { }, Category::Adjective => match word.declension_id { Some(id @ (1 | 3)) => { - if !ADJECTIVE_KINDS[id - 1].contains(&word.kind.as_str()) { + if !ADJECTIVE_KINDS[id as usize - 1].contains(&word.kind.as_str()) { return Err(format!("bad kind for declension '{id}'")); } } @@ -410,14 +410,14 @@ pub fn create_word(word: Word) -> Result<(), String> { params![ word.enunciated.trim(), word.particle.trim(), - word.language as usize, + word.language as isize, word.declension_id, word.conjugation_id, word.kind.trim(), - word.category as usize, + word.category as isize, word.regular, word.locative, - word.gender as usize, + word.gender as isize, word.suffix, serde_json::to_string(&word.flags).unwrap(), serde_json::to_string(&word.translation).unwrap(), @@ -451,10 +451,10 @@ pub fn update_word(word: Word) -> Result<(), String> { word.declension_id, word.conjugation_id, word.kind, - word.category as usize, + word.category as isize, word.regular, word.locative, - word.gender as usize, + word.gender as isize, word.suffix, serde_json::to_string(&word.flags).unwrap(), serde_json::to_string(&word.translation).unwrap(), @@ -514,14 +514,14 @@ pub fn find_by(enunciated: &str) -> Result<Word, String> { id: row.get(0).unwrap(), enunciated: row.get(1).unwrap(), particle: row.get(2).unwrap(), - language: row.get::<usize, usize>(3).unwrap().try_into()?, + language: row.get::<usize, isize>(3).unwrap().try_into()?, declension_id: row.get(4).unwrap(), conjugation_id: row.get(5).unwrap(), kind: row.get(6).unwrap(), - category: row.get::<usize, usize>(7).unwrap().try_into()?, + category: row.get::<usize, isize>(7).unwrap().try_into()?, regular: row.get(8).unwrap(), locative: row.get(9).unwrap(), - gender: row.get::<usize, usize>(10).unwrap().try_into()?, + gender: row.get::<usize, isize>(10).unwrap().try_into()?, suffix: row.get(11).unwrap(), translation: serde_json::from_str(&row.get::<usize, String>(12).unwrap()).unwrap(), succeeded: row.get(13).unwrap(), @@ -556,7 +556,7 @@ fn flags_clause(flags: &Vec<String>) -> String { pub fn select_relevant_words( category: Category, flags: &Vec<String>, - number: usize, + number: isize, ) -> Result<Vec<Word>, String> { let conn = get_connection()?; let mut stmt = conn @@ -574,7 +574,7 @@ pub fn select_relevant_words( .as_str(), ) .unwrap(); - let mut it = stmt.query([category as usize, number]).unwrap(); + let mut it = stmt.query([category as isize, number]).unwrap(); let mut res = vec![]; while let Some(row) = it.next().unwrap() { @@ -582,14 +582,14 @@ pub fn select_relevant_words( id: row.get(0).unwrap(), enunciated: row.get(1).unwrap(), particle: row.get(2).unwrap(), - language: row.get::<usize, usize>(3).unwrap().try_into()?, + language: row.get::<usize, isize>(3).unwrap().try_into()?, declension_id: row.get(4).unwrap(), conjugation_id: row.get(5).unwrap(), kind: row.get(6).unwrap(), - category: row.get::<usize, usize>(7).unwrap().try_into()?, + category: row.get::<usize, isize>(7).unwrap().try_into()?, regular: row.get(8).unwrap(), locative: row.get(9).unwrap(), - gender: row.get::<usize, usize>(10).unwrap().try_into()?, + gender: row.get::<usize, isize>(10).unwrap().try_into()?, suffix: row.get(11).unwrap(), translation: serde_json::from_str(&row.get::<usize, String>(12).unwrap()).unwrap(), succeeded: row.get(13).unwrap(), @@ -601,7 +601,7 @@ pub fn select_relevant_words( Ok(res) } -pub fn update_success(word: &Word, success: usize, steps: usize) -> Result<(), String> { +pub fn update_success(word: &Word, success: isize, steps: isize) -> Result<(), String> { let conn = get_connection()?; match conn.execute( @@ -659,10 +659,10 @@ impl std::fmt::Display for ExerciseKind { } } -impl TryFrom<usize> for ExerciseKind { +impl TryFrom<isize> for ExerciseKind { type Error = &'static str; - fn try_from(value: usize) -> Result<Self, Self::Error> { + fn try_from(value: isize) -> Result<Self, Self::Error> { match value { 0 => Ok(Self::Pensum), 1 => Ok(Self::Translation), @@ -709,7 +709,7 @@ pub fn create_exercise(exercise: Exercise) -> Result<(), String> { exercise.enunciate, exercise.solution, exercise.lessons, - exercise.kind as usize, + exercise.kind as isize, ], ) { Ok(_) => Ok(()), @@ -765,7 +765,7 @@ pub fn find_exercise_by_title(title: &str) -> Result<Exercise, String> { enunciate: row.get(2).unwrap(), solution: row.get(3).unwrap(), lessons: row.get(4).unwrap(), - kind: row.get::<usize, usize>(5).unwrap().try_into()?, + kind: row.get::<usize, isize>(5).unwrap().try_into()?, }), None => Err("no exercises were found with this title".to_string()), }, @@ -791,7 +791,7 @@ pub fn update_exercise(exercise: Exercise) -> Result<(), String> { exercise.enunciate, exercise.solution, exercise.lessons, - exercise.kind as usize, + exercise.kind as isize, ], ) { Ok(_) => Ok(()), @@ -814,7 +814,7 @@ pub fn delete_exercise(title: &str) -> Result<(), String> { // by `kind`. pub fn select_relevant_exercises( kind: Option<ExerciseKind>, - limit: usize, + limit: isize, ) -> Result<Vec<Exercise>, String> { let conn = get_connection()?; @@ -830,7 +830,7 @@ pub fn select_relevant_exercises( LIMIT ?2", ) .unwrap(); - stmt.query([kind as usize, limit]).unwrap() + stmt.query([kind as isize, limit]).unwrap() } None => { stmt = conn @@ -853,7 +853,7 @@ pub fn select_relevant_exercises( enunciate: row.get(2).unwrap(), solution: row.get(3).unwrap(), lessons: row.get(4).unwrap(), - kind: row.get::<usize, usize>(5).unwrap().try_into()?, + kind: row.get::<usize, isize>(5).unwrap().try_into()?, }); } Ok(res) @@ -1093,17 +1093,24 @@ pub fn group_declension_inflections( while let Some(row) = it.next().unwrap() { // Fetch the number and account for defectives on number. - let number: usize = row.get(1).unwrap(); + let number_i: isize = row.get(1).unwrap(); + let number: usize = usize::try_from(number_i).expect("not expecting a negative number"); if (number == 0 && word.is_flag_set("onlyplural")) || (number == 1 && word.is_flag_set("onlysingular")) { continue; } - let case = row.get(3).unwrap(); + let case_i: isize = row.get(3).unwrap(); let term: String = row.get(4).unwrap(); - table.add(word, case, number, gender, &term); + table.add( + word, + usize::try_from(case_i).expect("not expecting a negative number"), + number, + gender, + &term, + ); } if let Some(sets) = word.flags.get("sets") { |
