Struct freedesktop_desktop_entry::DesktopEntry
source · pub struct DesktopEntry<'a> {
pub appid: Cow<'a, str>,
pub groups: Groups<'a>,
pub path: Cow<'a, Path>,
pub ubuntu_gettext_domain: Option<Cow<'a, str>>,
}
Fields§
§appid: Cow<'a, str>
§groups: Groups<'a>
§path: Cow<'a, Path>
§ubuntu_gettext_domain: Option<Cow<'a, str>>
Implementations§
source§impl<'a> DesktopEntry<'a>
impl<'a> DesktopEntry<'a>
sourcepub fn from_str<L>(
path: &'a Path,
input: &'a str,
locales: &[L],
) -> Result<DesktopEntry<'a>, DecodeError>
pub fn from_str<L>( path: &'a Path, input: &'a str, locales: &[L], ) -> Result<DesktopEntry<'a>, DecodeError>
Examples found in repository?
examples/all_files.rs (line 16)
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 29)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
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);
}
sourcepub fn from_paths<'i, 'l: 'i, L>(
paths: impl Iterator<Item = PathBuf> + 'i,
locales: &'l [L],
) -> impl Iterator<Item = Result<DesktopEntry<'static>, DecodeError>> + 'i
pub fn from_paths<'i, 'l: 'i, L>( paths: impl Iterator<Item = PathBuf> + 'i, locales: &'l [L], ) -> impl Iterator<Item = Result<DesktopEntry<'static>, DecodeError>> + 'i
Examples found in repository?
examples/bench.rs (line 67)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
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);
}
sourcepub fn from_path<L>(
path: PathBuf,
locales: &[L],
) -> Result<DesktopEntry<'static>, DecodeError>
pub fn from_path<L>( path: PathBuf, locales: &[L], ) -> Result<DesktopEntry<'static>, DecodeError>
Return an owned DesktopEntry
Examples found in repository?
examples/bench.rs (line 49)
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
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);
}
More examples
examples/specific_file.rs (line 15)
5 6 7 8 9 10 11 12 13 14 15 16 17 18
fn main() {
let path = Path::new("tests/org.mozilla.firefox.desktop");
let locales = &["fr_FR", "en", "it"];
// if let Ok(bytes) = fs::read_to_string(path) {
// if let Ok(entry) = DesktopEntry::decode_from_str(path, &bytes, locales) {
// println!("{}\n---\n{}", path.display(), entry);
// }
// }
if let Ok(entry) = DesktopEntry::from_path(path.to_path_buf(), locales) {
println!("{}\n---\n{}", path.display(), entry);
}
}
source§impl DesktopEntry<'_>
impl DesktopEntry<'_>
sourcepub fn from_appid(appid: &str) -> DesktopEntry<'_>
pub fn from_appid(appid: &str) -> DesktopEntry<'_>
Construct a new DesktopEntry
from an appid. The name field will be
set to that appid.
source§impl<'a> DesktopEntry<'a>
impl<'a> DesktopEntry<'a>
pub fn to_owned(&self) -> DesktopEntry<'static>
source§impl<'a> DesktopEntry<'a>
impl<'a> DesktopEntry<'a>
pub fn id(&'a self) -> &'a str
sourcepub fn desktop_entry(&'a self, key: &str) -> Option<&'a str>
pub fn desktop_entry(&'a self, key: &str) -> Option<&'a str>
A desktop entry field if any field under the [Desktop Entry]
section.
pub fn desktop_entry_localized<L: AsRef<str>>( &'a self, key: &str, locales: &[L], ) -> Option<Cow<'a, str>>
sourcepub fn add_desktop_entry<'b>(&'b mut self, key: &'a str, value: &'a str)where
'a: 'b,
pub fn add_desktop_entry<'b>(&'b mut self, key: &'a str, value: &'a str)where
'a: 'b,
Insert a new field to this DesktopEntry
, in the [Desktop Entry]
section, removing
the previous value and locales in any.
pub fn name<L: AsRef<str>>(&'a self, locales: &[L]) -> Option<Cow<'a, str>>
pub fn generic_name<L: AsRef<str>>( &'a self, locales: &[L], ) -> Option<Cow<'a, str>>
pub fn icon(&'a self) -> Option<&'a str>
sourcepub fn comment<L: AsRef<str>>(&'a self, locales: &[L]) -> Option<Cow<'a, str>>
pub fn comment<L: AsRef<str>>(&'a self, locales: &[L]) -> Option<Cow<'a, str>>
This is an human readable description of the desktop file.
pub fn exec(&'a self) -> Option<&'a str>
sourcepub fn categories(&'a self) -> Option<Vec<&'a str>>
pub fn categories(&'a self) -> Option<Vec<&'a str>>
Return categories
sourcepub fn keywords<L: AsRef<str>>(
&'a self,
locales: &[L],
) -> Option<Vec<Cow<'a, str>>>
pub fn keywords<L: AsRef<str>>( &'a self, locales: &[L], ) -> Option<Vec<Cow<'a, str>>>
Return keywords
pub fn no_display(&'a self) -> bool
pub fn only_show_in(&'a self) -> Option<Vec<&'a str>>
pub fn not_show_in(&'a self) -> Option<Vec<&'a str>>
pub fn flatpak(&'a self) -> Option<&'a str>
pub fn prefers_non_default_gpu(&'a self) -> bool
pub fn startup_notify(&'a self) -> bool
pub fn startup_wm_class(&'a self) -> Option<&'a str>
pub fn terminal(&'a self) -> bool
pub fn type_(&'a self) -> Option<&'a str>
pub fn actions(&'a self) -> Option<Vec<&'a str>>
sourcepub fn action_entry(&'a self, action: &str, key: &str) -> Option<&'a str>
pub fn action_entry(&'a self, action: &str, key: &str) -> Option<&'a str>
An action is defined as [Desktop Action actions-name]
where action-name
is defined in the Actions
field of [Desktop Entry]
.
Example: to get the Name
field of this new-window
action
[Desktop Action new-window]
Name=Open a New Window
you will need to call
ⓘ
entry.action_entry("new-window", "Name")
pub fn action_entry_localized<L: AsRef<str>>( &'a self, action: &str, key: &str, locales: &[L], ) -> Option<Cow<'a, str>>
pub fn action_name<L: AsRef<str>>( &'a self, action: &str, locales: &[L], ) -> Option<Cow<'a, str>>
pub fn action_exec(&'a self, action: &str) -> Option<&'a str>
pub fn localized_entry_splitted<L: AsRef<str>>( &self, group: Option<&'a KeyMap<'a>>, key: &str, locales: &[L], ) -> Option<Vec<Cow<'a, str>>>
Trait Implementations§
source§impl<'a> Clone for DesktopEntry<'a>
impl<'a> Clone for DesktopEntry<'a>
source§fn clone(&self) -> DesktopEntry<'a>
fn clone(&self) -> DesktopEntry<'a>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'a> Debug for DesktopEntry<'a>
impl<'a> Debug for DesktopEntry<'a>
source§impl<'a> Display for DesktopEntry<'a>
impl<'a> Display for DesktopEntry<'a>
source§impl Hash for DesktopEntry<'_>
impl Hash for DesktopEntry<'_>
source§impl PartialEq for DesktopEntry<'_>
impl PartialEq for DesktopEntry<'_>
impl<'a> Eq for DesktopEntry<'a>
Auto Trait Implementations§
impl<'a> Freeze for DesktopEntry<'a>
impl<'a> RefUnwindSafe for DesktopEntry<'a>
impl<'a> Send for DesktopEntry<'a>
impl<'a> Sync for DesktopEntry<'a>
impl<'a> Unpin for DesktopEntry<'a>
impl<'a> UnwindSafe for DesktopEntry<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more