Skip to content

Commit 5aa2fa0

Browse files
author
Brendan Molloy
committed
Add is_correct and fix archive creation exception
1 parent 781279f commit 5aa2fa0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ crate-type = ["cdylib"]
1515
divvunspell = { git = "https://github.com/divvun/divvunspell", branch = "main", features = ["compression"] }
1616

1717
[dependencies.pyo3]
18-
version = "0.13.4"
18+
version = "0.13.2"
1919
features = ["extension-module"]
2020

2121
[package.metadata.maturin]

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ struct SpellerArchive {
4646
impl SpellerArchive {
4747
#[new]
4848
fn new(path: String) -> PyResult<Self> {
49-
let ar = archive::open(std::path::Path::new(&path)).unwrap();
49+
let ar = archive::open(std::path::Path::new(&path))
50+
.map_err(|e| PyErr::new::<pyo3::exceptions::PyException, _>(format!("{}", e)))?;
5051
Ok(SpellerArchive { archive: ar })
5152
}
5253

@@ -87,4 +88,10 @@ impl Speller {
8788
.map(|x| (x.value.to_string(), x.weight))
8889
.collect::<Vec<_>>())
8990
}
91+
92+
/// Returns whether a word is spelt correctly.
93+
fn is_correct(&self, word: String) -> PyResult<bool> {
94+
let speller = Arc::clone(&self.speller);
95+
Ok(speller.is_correct(&word))
96+
}
9097
}

0 commit comments

Comments
 (0)