Function freedesktop_desktop_entry::default_paths
source ยท pub fn default_paths() -> Vec<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, in reverse, e.i the path with the greater priority will be at the end.
Panics in case determining the current home directory fails.
Examples found in repository?
examples/all_files.rs (line 13)
10 11 12 13 14 15 16 17 18 19 20 21
fn main() {
let locales = get_languages_from_env();
for path in Iter::new(default_paths()) {
let path_src = PathSource::guess_from(&path);
if let Ok(bytes) = fs::read_to_string(&path) {
if let Ok(entry) = DesktopEntry::from_str(&path, &bytes, &locales) {
println!("{:?}: {}\n---\n{}", path_src, path.display(), entry);
}
}
}
}More 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 74 75
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, &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, &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 _ = DesktopEntry::from_paths(paths, &locale)
.filter_map(|e| e.ok())
.collect::<Vec<_>>();
total_time += now.elapsed();
}
println!("bench_owned_optimized: {:.2?}", total_time / it);
}