Function default_paths

Source
pub fn default_paths() -> impl Iterator<Item = PathBuf>
Expand description

Returns the default paths in which desktop entries should be searched for based on the current environment. Paths are sorted by priority.

Panics in case determining the current home directory fails.

Examples found in repository?
examples/all_files.rs (line 9)
6fn main() {
7    let locales = get_languages_from_env();
8
9    let entries = Iter::new(default_paths())
10        .entries(Some(&locales))
11        .collect::<Vec<_>>();
12
13    for entry in entries {
14        let path_src = PathSource::guess_from(&entry.path);
15
16        println!("{:?}: {}\n---\n{}", path_src, entry.path.display(), entry);
17    }
18}
More examples
Hide additional examples
examples/bench.rs (line 21)
16fn bench(it: u32) {
17    let mut total_time = Duration::ZERO;
18
19    for _ in 0..it {
20        let locale = get_languages_from_env();
21        let paths = Iter::new(default_paths());
22
23        let now = Instant::now();
24
25        for path in paths {
26            if let Ok(bytes) = fs::read_to_string(&path) {
27                if let Ok(_entry) = DesktopEntry::from_str(&path, &bytes, Some(&locale)) {}
28            }
29        }
30
31        total_time += now.elapsed();
32    }
33
34    println!("time to parse all .desktop files: {:.2?}", total_time / it);
35}