win_font_dir/
lib.rs

1use std::{env, path::PathBuf};
2
3/// Returns the path to user's font directory.
4pub fn user_font_dir() -> Option<PathBuf> {
5    env::var_os("LOCALAPPDATA").and_then(|x| {
6        let path = PathBuf::from(x).join("Microsoft\\Windows\\Fonts");
7        if path.is_dir() {
8            Some(path)
9        } else {
10            None
11        }
12    })
13}
14
15/// Returns the path to system's font directory.
16pub fn system_font_dir() -> Option<PathBuf> {
17    env::var_os("windir").and_then(|x| {
18        let path = PathBuf::from(x).join("Fonts");
19        if path.is_dir() {
20            Some(path)
21        } else {
22            None
23        }
24    })
25}
26
27#[cfg(test)]
28mod tests {
29    use super::{system_font_dir, user_font_dir};
30
31    #[test]
32    fn test() {
33        println!(
34            "user font dir:   {}",
35            user_font_dir().unwrap().to_str().unwrap()
36        );
37        println!(
38            "system font dir: {}",
39            system_font_dir().unwrap().to_str().unwrap()
40        );
41    }
42}