30
30
//! ```
31
31
32
32
#[ cfg( target_os = "windows" ) ]
33
- pub use windows:: { that , with } ;
33
+ use windows as os ;
34
34
35
35
#[ cfg( target_os = "macos" ) ]
36
- pub use macos:: { that , with } ;
36
+ use macos as os ;
37
37
38
38
#[ cfg( target_os = "ios" ) ]
39
- pub use ios:: { that , with } ;
39
+ use ios as os ;
40
40
41
41
#[ cfg( any(
42
42
target_os = "linux" ,
@@ -47,7 +47,7 @@ pub use ios::{that, with};
47
47
target_os = "openbsd" ,
48
48
target_os = "solaris"
49
49
) ) ]
50
- pub use unix:: { that , with } ;
50
+ use unix as os ;
51
51
52
52
#[ cfg( not( any(
53
53
target_os = "linux" ,
@@ -72,13 +72,60 @@ use std::{
72
72
73
73
type Result = io:: Result < ( ) > ;
74
74
75
- /// Convenience function for opening the passed path in a new thread.
76
- /// See documentation of `that(...)` for more details.
75
+ /// Open path with the default application.
76
+ ///
77
+ /// # Examples
78
+ ///
79
+ /// ```
80
+ /// let path = "http://rust-lang.org";
81
+ ///
82
+ /// match open::that(path) {
83
+ /// Ok(()) => println!("Opened '{}' successfully.", path),
84
+ /// Err(err) => panic!("An error occurred when opening '{}': {}", path, err),
85
+ /// }
86
+ /// ```
87
+ ///
88
+ /// # Errors
89
+ ///
90
+ /// A [`std::io::Error`] is returned on failure. Because different operating systems
91
+ /// handle errors differently it is recommend to not match on a certain error.
92
+ pub fn that < T : AsRef < OsStr > + Sized > ( path : T ) -> Result {
93
+ os:: that ( path)
94
+ }
95
+
96
+ /// Open path with the given application.
97
+ ///
98
+ /// # Examples
99
+ ///
100
+ /// ```
101
+ /// let path = "http://rust-lang.org";
102
+ /// let app = "firefox";
103
+ ///
104
+ /// match open::with(path, app) {
105
+ /// Ok(()) => println!("Opened '{}' successfully.", path),
106
+ /// Err(err) => panic!("An error occurred when opening '{}': {}", path, err),
107
+ /// }
108
+ /// ```
109
+ ///
110
+ /// # Errors
111
+ ///
112
+ /// A [`std::io::Error`] is returned on failure. Because different operating systems
113
+ /// handle errors differently it is recommend to not match on a certain error.
114
+ pub fn with < T : AsRef < OsStr > + Sized > ( path : T , app : impl Into < String > ) -> Result {
115
+ os:: with ( path, app)
116
+ }
117
+
118
+ /// Open path with the default application in a new thread.
119
+ ///
120
+ /// See documentation of [`that`] for more details.
77
121
pub fn that_in_background < T : AsRef < OsStr > + Sized > ( path : T ) -> thread:: JoinHandle < Result > {
78
122
let path = path. as_ref ( ) . to_os_string ( ) ;
79
123
thread:: spawn ( || that ( path) )
80
124
}
81
125
126
+ /// Open path with the given application in a new thread.
127
+ ///
128
+ /// See documentation of [`with`] for more details.
82
129
pub fn with_in_background < T : AsRef < OsStr > + Sized > (
83
130
path : T ,
84
131
app : impl Into < String > ,
0 commit comments