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>

source

pub fn from_str<L>( path: &'a Path, input: &'a str, locales: &[L], ) -> Result<DesktopEntry<'a>, DecodeError>
where L: AsRef<str>,

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
Hide additional 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);
}
source

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
where L: AsRef<str>,

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);
}
source

pub fn from_path<L>( path: PathBuf, locales: &[L], ) -> Result<DesktopEntry<'static>, DecodeError>
where L: AsRef<str>,

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
Hide additional 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<'_>

source

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>

source

pub fn to_owned(&self) -> DesktopEntry<'static>

source§

impl<'a> DesktopEntry<'a>

source

pub fn id(&'a self) -> &'a str

source

pub fn desktop_entry(&'a self, key: &str) -> Option<&'a str>

A desktop entry field if any field under the [Desktop Entry] section.

source

pub fn desktop_entry_localized<L: AsRef<str>>( &'a self, key: &str, locales: &[L], ) -> Option<Cow<'a, str>>

source

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.

source

pub fn name<L: AsRef<str>>(&'a self, locales: &[L]) -> Option<Cow<'a, str>>

source

pub fn generic_name<L: AsRef<str>>( &'a self, locales: &[L], ) -> Option<Cow<'a, str>>

source

pub fn icon(&'a self) -> Option<&'a str>

source

pub fn comment<L: AsRef<str>>(&'a self, locales: &[L]) -> Option<Cow<'a, str>>

This is an human readable description of the desktop file.

source

pub fn exec(&'a self) -> Option<&'a str>

source

pub fn categories(&'a self) -> Option<Vec<&'a str>>

Return categories

source

pub fn keywords<L: AsRef<str>>( &'a self, locales: &[L], ) -> Option<Vec<Cow<'a, str>>>

Return keywords

source

pub fn mime_type(&'a self) -> Option<Vec<&'a str>>

Return mime types

source

pub fn no_display(&'a self) -> bool

source

pub fn only_show_in(&'a self) -> Option<Vec<&'a str>>

source

pub fn not_show_in(&'a self) -> Option<Vec<&'a str>>

source

pub fn flatpak(&'a self) -> Option<&'a str>

source

pub fn prefers_non_default_gpu(&'a self) -> bool

source

pub fn startup_notify(&'a self) -> bool

source

pub fn startup_wm_class(&'a self) -> Option<&'a str>

source

pub fn terminal(&'a self) -> bool

source

pub fn type_(&'a self) -> Option<&'a str>

source

pub fn actions(&'a self) -> Option<Vec<&'a str>>

source

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")
source

pub fn action_entry_localized<L: AsRef<str>>( &'a self, action: &str, key: &str, locales: &[L], ) -> Option<Cow<'a, str>>

source

pub fn action_name<L: AsRef<str>>( &'a self, action: &str, locales: &[L], ) -> Option<Cow<'a, str>>

source

pub fn action_exec(&'a self, action: &str) -> Option<&'a str>

source

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>

source§

fn clone(&self) -> DesktopEntry<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for DesktopEntry<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Display for DesktopEntry<'a>

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for DesktopEntry<'_>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for DesktopEntry<'_>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.