Function parse_entry Copy item path Source pub fn parse_entry(input: impl AsRef <Path >) -> Result <Entry >Expand description Parse a FreeDesktop entry file.
§ Example
use freedesktop_entry_parser::parse_entry;
let entry = parse_entry("./test_data/sshd.service" )? ;
let start_cmd = & entry
.get("Service" , "ExecStart" )
.expect("File doesn't have Service -> ExecStart" )[0 ];
assert_eq! (start_cmd, "/usr/bin/sshd -D" );§ Errors
If there is a parse error it’ll be return an ParseError wrapped std::io::Error
with the std::io::ErrorKind::Other .
use freedesktop_entry_parser::parse_entry;
match parse_entry("./test_data/sshd.service" ) {
Ok (entry) => println! ("{entry:#?}" ),
Err (e) if e.kind() == std::io::ErrorKind::Other => println! ("Parse error {e:?}" ),
Err (e) => println! ("I/O Error {e:?}" ),
}examples/systemd_start_cmd.rs (
line 5 )
4 fn main() -> Result <()> {
5 let entry = parse_entry ("./test_data/sshd.service" )? ;
6 let start_cmd = & entry
7 .section("Service" )
8 .expect("Section Service doesn't exist" )
9 .attr("ExecStart" )[0 ];
10 println! ("{}" , start_cmd);
11 Ok (())
12 }More examples Hide additional examples
examples/get_localized_name.rs (
line 5 )
3 fn main() -> std::io::Result<()> {
4 let lang = std::env::args().nth(1 ).expect("Not enough args" );
5 let entry = parse_entry ("./test_data/firefox.desktop" )? ;
6 let desktop_section = entry.section("Desktop Entry" ).unwrap();
7 match desktop_section.attr_with_param("GenericName" , lang).get(0 ) {
8 Some (localized_name) => println! ("{localized_name}" ),
9 None => println! ("No name for that lang" ),
10 }
11 Ok (())
12 }