Skip to content

Commit 4506b2f

Browse files
committed
split into two functions for better readability
1 parent 191cb0e commit 4506b2f

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/windows.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,34 @@ fn wrap_in_quotes<T: AsRef<OsStr>>(path: T) -> OsString {
4040
}
4141

4242
pub fn that_detached<T: AsRef<OsStr>>(path: T) -> std::io::Result<()> {
43-
detached(path, None::<&str>)
44-
}
43+
let path = wide(path);
4544

46-
pub fn with_detached<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> std::io::Result<()> {
47-
detached(path, Some(app))
45+
unsafe {
46+
ShellExecuteW(
47+
0,
48+
ffi::OPEN,
49+
path.as_ptr(),
50+
ptr::null(),
51+
ptr::null(),
52+
ffi::SW_SHOW,
53+
)
54+
}
4855
}
4956

50-
#[inline]
51-
fn detached<T: AsRef<OsStr>>(path: T, app: Option<impl Into<String>>) -> std::io::Result<()> {
57+
pub fn with_detached<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> std::io::Result<()> {
58+
let app = wide(app.into());
5259
let path = wide(path);
53-
let app = app.map(|a| wide(a.into()));
54-
55-
let (app, args) = match app {
56-
Some(app) => (app.as_ptr(), path.as_ptr()),
57-
None => (path.as_ptr(), ptr::null()),
58-
};
5960

60-
unsafe { ShellExecuteW(0, ffi::OPEN, app, args, ptr::null(), ffi::SW_SHOW) }
61+
unsafe {
62+
ShellExecuteW(
63+
0,
64+
ffi::OPEN,
65+
app.as_ptr(),
66+
path.as_ptr(),
67+
ptr::null(),
68+
ffi::SW_SHOW,
69+
)
70+
}
6171
}
6272

6373
/// Encodes as wide and adds a null character.

0 commit comments

Comments
 (0)