[−][src]Module spandex_hyphenation::load
Reading and loading hyphenation dictionaries
To hyphenate words in a given language, it is first necessary to load
the relevant hyphenation dictionary into memory. This module offers
convenience methods for common retrieval patterns, courtesy of the
Load
trait.
use hyphenation::Load; use hyphenation::{Standard, Language};
The primary function of Load
is to deserialize dictionaries from
buffers – usually, file buffers.
use std::io;
use std::fs::File;
let path_to_dict = "/path/to/english-dictionary.bincode";
let dict_file = File::open(path_to_dict) ?;
let mut reader = io::BufReader::new(dict_file);
let english_us = Standard::from_reader(Language::EnglishUS, &mut reader) ?;
Dictionaries can be loaded from the file system rather more succintly with
the from_path
shorthand:
let path_to_dict = "/path/to/english-dictionary.bincode";
let english_us = Standard::from_path(Language::EnglishUS, path_to_dict) ?;
Dictionaries bundled with the hyphenation
library are copied to Cargo's
output directory at build time. To locate them, look for a dictionaries
folder under target
:
$ find target -name "dictionaries" target/debug/build/hyphenation-33034db3e3b5f3ce/out/dictionaries
Embedding
Optionally, hyphenation dictionaries can be embedded in the compiled
artifact by enabling the embed_all
feature. Embedded dictionaries can be
accessed directly from memory.
use hyphenation::{Standard, Language, Load}; let english_us = Standard::from_embedded(Language::EnglishUS) ?;
Note that embeding significantly increases the size of the compiled artifact.
Enums
Error | Failure modes of dictionary loading. |
Traits
Load | Convenience methods for the retrieval of hyphenation dictionaries. |
Type Definitions
Result |