Function opener::open

source ·
pub fn open<P>(path: P) -> Result<(), OpenError>
where P: AsRef<OsStr>,
Expand description

Opens a file or link with the system default program.

Note that a path like “rustup.rs” could potentially refer to either a file or a website. If you want to open the website, you should add the “http://” prefix, for example.

Also note that a result of Ok(()) just means a way of opening the path was found, and no error occurred as a direct result of opening the path. Errors beyond that point aren’t caught. For example, Ok(()) would be returned even if a file was opened with a program that can’t read the file, or a dead link was opened in a browser.

§Platform Implementation Details

  • On Windows the ShellExecuteW Windows API function is used.
  • On Mac the system open command is used.
  • On Windows Subsystem for Linux (WSL), the system wslview from wslu is used if available, otherwise the system xdg-open is used, if available.
  • On non-WSL Linux and other platforms, the system xdg-open script is used if available, otherwise an xdg-open script embedded in this library is used.