Function freedesktop_desktop_entry::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 8)
6
7
8
9
10
11
12
13
fn main() {
    let locales = get_languages_from_env();
    for entry in Iter::new(default_paths()).entries(Some(&locales)) {
        let path_src = PathSource::guess_from(&entry.path);

        println!("{:?}: {}\n---\n{}", path_src, entry.path.display(), entry);
    }
}
More examples
Hide additional examples
examples/bench.rs (line 23)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
fn bench_borrowed(it: u32) {
    let mut total_time = Duration::ZERO;

    for _ in 0..it {
        let locale = get_languages_from_env();
        let paths = Iter::new(default_paths());

        let now = Instant::now();

        for path in paths {
            if let Ok(bytes) = fs::read_to_string(&path) {
                if let Ok(_entry) = DesktopEntry::from_str(&path, &bytes, Some(&locale)) {}
            }
        }

        total_time += now.elapsed();
    }

    println!("bench_borrowed: {:.2?}", total_time / it);
}

fn bench_owned(it: u32) {
    let mut total_time = Duration::ZERO;

    for _ in 0..it {
        let locale = get_languages_from_env();
        let paths = Iter::new(default_paths());

        let now = Instant::now();

        for path in paths {
            if let Ok(_entry) = DesktopEntry::from_path(path, Some(&locale)) {}
        }

        total_time += now.elapsed();
    }

    println!("bench_owned: {:.2?}", total_time / it);
}

fn bench_owned_optimized(it: u32) {
    let mut total_time = Duration::ZERO;

    for _ in 0..it {
        let locale = get_languages_from_env();
        let paths = Iter::new(default_paths());

        let now = Instant::now();

        let _ = paths.entries(Some(&locale)).collect::<Vec<_>>();

        total_time += now.elapsed();
    }

    println!("bench_owned_optimized: {:.2?}", total_time / it);
}