pub struct DesktopFile { /* private fields */ }Expand description
An in-memory, order-preserving view of a .desktop file.
use runlatch_core::desktop_file::{DesktopFile, DESKTOP_ENTRY_GROUP};
let mut file = DesktopFile::parse("[Desktop Entry]\nName=Example\nExec=example\n");
assert_eq!(file.get(DESKTOP_ENTRY_GROUP, "Name"), Some("Example"));
// Editing one key leaves everything else byte-for-byte intact.
file.set(DESKTOP_ENTRY_GROUP, "Hidden", "true");
assert_eq!(
file.to_text(),
"[Desktop Entry]\nName=Example\nExec=example\nHidden=true\n",
);Implementations§
Source§impl DesktopFile
impl DesktopFile
Sourcepub fn parse(text: &str) -> Self
pub fn parse(text: &str) -> Self
Parse desktop-file text into an editable, order-preserving model.
Sourcepub fn to_text(&self) -> String
pub fn to_text(&self) -> String
Serialize back to desktop-file text (always newline-terminated).
Sourcepub fn get(&self, group: &str, key: &str) -> Option<&str>
pub fn get(&self, group: &str, key: &str) -> Option<&str>
Get the value of key within group, if present.
Trait Implementations§
Source§impl Clone for DesktopFile
impl Clone for DesktopFile
Source§fn clone(&self) -> DesktopFile
fn clone(&self) -> DesktopFile
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DesktopFile
impl Debug for DesktopFile
Source§impl Default for DesktopFile
impl Default for DesktopFile
Source§fn default() -> DesktopFile
fn default() -> DesktopFile
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for DesktopFile
impl RefUnwindSafe for DesktopFile
impl Send for DesktopFile
impl Sync for DesktopFile
impl Unpin for DesktopFile
impl UnsafeUnpin for DesktopFile
impl UnwindSafe for DesktopFile
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