Skip to content

Commit ff32bea

Browse files
committed
Merge pull request #2 from hoodie/master
taking T:AsRef<OsStr> instead of &str
2 parents 31605e0 + 2540a0a commit ff32bea

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/lib.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,29 @@
44
//!
55
//! ```test_harness,no_run
66
//! extern crate open;
7-
//!
7+
//!
88
//! # #[test]
99
//! # fn doit() {
1010
//! open::that("/path/to/file/with.fancy-extension");
11-
//! if open::that("https://google.de").is_ok() {
11+
//! if open::that("https://rust-lang.org").is_ok() {
1212
//! println!("Look at your browser !");
1313
//! }
1414
//! # }
1515
//! ```
1616
//!
1717
//! # Notes
1818
//! As an operating system program is used, chances are that the open operation fails.
19-
//! Therfore, you are advised to at least check the result with `.is_err()` and
19+
//! Therfore, you are advised to at least check the result with `.is_err()` and
2020
//! behave accordingly, e.g. by letting the user know what you tried to open, and failed.
2121
use std::io;
2222
use std::process::{Command, ExitStatus};
23+
use std::ffi::OsStr;
2324

2425
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
25-
pub fn that(path: &str) -> io::Result<ExitStatus> {
26+
pub fn that<T:AsRef<OsStr>+Sized>(path: T) -> io::Result<ExitStatus> {
2627
let mut last_err: io::Result<ExitStatus> = Err(io::Error::from_raw_os_error(0));
2728
for program in &["xdg-open", "gnome-open", "kde-open"] {
28-
match Command::new(program).arg(path).spawn() {
29+
match Command::new(program).arg(path.as_ref()).spawn() {
2930
Ok(mut child) => return child.wait(),
3031
Err(err) => {
3132
last_err = Err(err);
@@ -37,11 +38,11 @@ pub fn that(path: &str) -> io::Result<ExitStatus> {
3738
}
3839

3940
#[cfg(target_os = "windows")]
40-
pub fn that(path: &str) -> io::Result<ExitStatus> {
41-
try!(Command::new("cmd").arg("/C").arg("start").arg(path).spawn()).wait()
41+
pub fn that<T:AsRef<OsStr>+Sized>(path: T) -> io::Result<ExitStatus> {
42+
try!(Command::new("cmd").arg("/C").arg("start").arg(path.as_ref()).spawn()).wait()
4243
}
4344

4445
#[cfg(target_os = "macos")]
45-
pub fn that(path: &str) -> io::Result<ExitStatus> {
46-
try!(Command::new("open").arg(path).spawn()).wait()
46+
pub fn that<T:AsRef<OsStr>+Sized>(path: T) -> io::Result<ExitStatus> {
47+
try!(Command::new("open").arg(path.as_ref()).spawn()).wait()
4748
}

0 commit comments

Comments
 (0)