diff --git a/src/lib.rs b/src/lib.rs index 4231591..d274343 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,11 +4,11 @@ //! //! ```test_harness,no_run //! extern crate open; -//! +//! //! # #[test] //! # fn doit() { //! open::that("/path/to/file/with.fancy-extension"); -//! if open::that("https://google.de").is_ok() { +//! if open::that("https://rust-lang.org").is_ok() { //! println!("Look at your browser !"); //! } //! # } @@ -16,16 +16,17 @@ //! //! # Notes //! As an operating system program is used, chances are that the open operation fails. -//! Therfore, you are advised to at least check the result with `.is_err()` and +//! Therfore, you are advised to at least check the result with `.is_err()` and //! behave accordingly, e.g. by letting the user know what you tried to open, and failed. use std::io; use std::process::{Command, ExitStatus}; +use std::ffi::OsStr; #[cfg(not(any(target_os = "windows", target_os = "macos")))] -pub fn that(path: &str) -> io::Result { +pub fn that+Sized>(path: T) -> io::Result { let mut last_err: io::Result = Err(io::Error::from_raw_os_error(0)); for program in &["xdg-open", "gnome-open", "kde-open"] { - match Command::new(program).arg(path).spawn() { + match Command::new(program).arg(path.as_ref()).spawn() { Ok(mut child) => return child.wait(), Err(err) => { last_err = Err(err); @@ -37,11 +38,11 @@ pub fn that(path: &str) -> io::Result { } #[cfg(target_os = "windows")] -pub fn that(path: &str) -> io::Result { - try!(Command::new("cmd").arg("/C").arg("start").arg(path).spawn()).wait() +pub fn that+Sized>(path: T) -> io::Result { + try!(Command::new("cmd").arg("/C").arg("start").arg(path.as_ref()).spawn()).wait() } #[cfg(target_os = "macos")] -pub fn that(path: &str) -> io::Result { - try!(Command::new("open").arg(path).spawn()).wait() +pub fn that+Sized>(path: T) -> io::Result { + try!(Command::new("open").arg(path.as_ref()).spawn()).wait() }