Skip to content

Rust API

The odict crate is the core library that powers the CLI and all language bindings. It is published on crates.io.

Add to your Cargo.toml:

[dependencies]
odict = "3"

Full API documentation is available on docs.rs. Use these docs for exhaustive method signatures, trait details, and module-level examples:

docs.rs/odict

This page focuses on the decisions you need before using the crate: installation, feature flags, and the main entry points.

The odict crate uses feature flags to control which capabilities are compiled in. The default feature includes sql and config.

FeatureDescription
defaultEnables sql and config
sqlSQL dump support (SQLite, PostgreSQL, MySQL) via sea-query
configAccess to platform-specific config directories
aliasDictionary alias management (implies config)
searchFull-text search via Tantivy (implies config)
markdownMarkdown rendering support via pulldown-cmark
htmlHTML output support (implies markdown)
httpRemote dictionary downloading (implies config)
tokenizeFull multi-language tokenization (enables all language tokenizers)
tokenize-latinLatin-script tokenization
tokenize-chineseChinese segmentation
tokenize-japaneseJapanese segmentation (UniDic)
tokenize-koreanKorean segmentation
tokenize-thaiThai segmentation
tokenize-khmerKhmer segmentation
tokenize-swedishSwedish recomposition
tokenize-germanGerman segmentation
use odict::{OpenDictionary, ToDictionary};
fn main() -> odict::Result<()> {
// Compile from XML
let xml = r#"
<dictionary name="Example">
<entry term="hello">
<ety>
<sense pos="intj">
<definition value="A greeting" />
</sense>
</ety>
</entry>
</dictionary>
"#;
// Compile and write to disk
let dict = xml.to_dictionary()?.build()?;
dict.to_disk("example.odict")?;
// Read from disk
let file = OpenDictionary::from_path("example.odict")?;
let contents = file.contents()?;
// Lookup
let results = contents.lookup(
&["hello"],
&odict::lookup::LookupOptions::default(),
)?;
println!("{:?}", results);
Ok(())
}
TypeDescription
OpenDictionaryA compiled dictionary loaded from disk or bytes
ToDictionaryTrait for converting XML strings to Dictionary
DictionaryThe deserialized dictionary schema type
CompilerOptionsOptions for compiling (compression settings)
lookup::LookupOptionsOptions for exact-match lookups
search::SearchOptionsOptions for full-text search
index::IndexOptionsOptions for creating a search index
tokenize::TokenizeOptionsOptions for text tokenization

For complete details on all types, traits, and methods, use the published crate documentation.