Skip to main content

espeak_ng_data_dict_sjn/
lib.rs

1//! eSpeak NG dictionary data for `sjn_dict`, embedded at compile time.
2//!
3//! ## Usage
4//!
5//! ```rust,no_run
6//! use std::path::Path;
7//!
8//! let data_dir = Path::new("/tmp/espeak-data");
9//! espeak_ng_data_dict_sjn::install(data_dir).unwrap();
10//! ```
11
12include!(concat!(env!("OUT_DIR"), "/files.rs"));
13
14/// Install the embedded `sjn_dict` into `dest_dir`.
15pub fn install(dest_dir: &std::path::Path) -> std::io::Result<()> {
16    for (rel_path, data) in ALL_FILES {
17        let dest = dest_dir.join(rel_path);
18        if let Some(parent) = dest.parent() {
19            std::fs::create_dir_all(parent)?;
20        }
21        std::fs::write(dest, data)?;
22    }
23    Ok(())
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn all_files_nonempty() {
32        assert!(!ALL_FILES.is_empty(), "ALL_FILES must not be empty");
33        for (path, data) in ALL_FILES {
34            assert!(!data.is_empty(), "embedded file {path:?} is empty");
35        }
36    }
37}