diff options
Diffstat (limited to 'crates/stdx')
-rw-r--r-- | crates/stdx/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/stdx/src/lib.rs | 14 |
2 files changed, 11 insertions, 5 deletions
diff --git a/crates/stdx/Cargo.toml b/crates/stdx/Cargo.toml index f78c5da7c..a6727ed2f 100644 --- a/crates/stdx/Cargo.toml +++ b/crates/stdx/Cargo.toml | |||
@@ -20,5 +20,7 @@ miow = "0.3.6" | |||
20 | winapi = "0.3.9" | 20 | winapi = "0.3.9" |
21 | 21 | ||
22 | [features] | 22 | [features] |
23 | default = [] | ||
24 | unix_stuff = [] | ||
23 | # Uncomment to enable for the whole crate graph | 25 | # Uncomment to enable for the whole crate graph |
24 | # default = [ "backtrace" ] | 26 | # default = [ "backtrace" ] |
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 2963484fa..027830134 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | use std::{cmp::Ordering, ops, time::Instant}; | 2 | use std::{cmp::Ordering, ops, time::Instant}; |
3 | 3 | ||
4 | mod macros; | 4 | mod macros; |
5 | #[cfg(feature = "unix_stuff")] | ||
5 | pub mod process; | 6 | pub mod process; |
6 | pub mod panic_context; | 7 | pub mod panic_context; |
7 | 8 | ||
@@ -110,9 +111,12 @@ pub fn defer<F: FnOnce()>(f: F) -> impl Drop { | |||
110 | D(Some(f)) | 111 | D(Some(f)) |
111 | } | 112 | } |
112 | 113 | ||
113 | #[cfg_attr(not(target_arch = "wasm32"), repr(transparent))] | 114 | |
115 | #[cfg(feature = "unix_stuff")] | ||
116 | #[repr(transparent)] | ||
114 | pub struct JodChild(pub std::process::Child); | 117 | pub struct JodChild(pub std::process::Child); |
115 | 118 | ||
119 | #[cfg(feature = "unix_stuff")] | ||
116 | impl ops::Deref for JodChild { | 120 | impl ops::Deref for JodChild { |
117 | type Target = std::process::Child; | 121 | type Target = std::process::Child; |
118 | fn deref(&self) -> &std::process::Child { | 122 | fn deref(&self) -> &std::process::Child { |
@@ -120,12 +124,14 @@ impl ops::Deref for JodChild { | |||
120 | } | 124 | } |
121 | } | 125 | } |
122 | 126 | ||
127 | #[cfg(feature = "unix_stuff")] | ||
123 | impl ops::DerefMut for JodChild { | 128 | impl ops::DerefMut for JodChild { |
124 | fn deref_mut(&mut self) -> &mut std::process::Child { | 129 | fn deref_mut(&mut self) -> &mut std::process::Child { |
125 | &mut self.0 | 130 | &mut self.0 |
126 | } | 131 | } |
127 | } | 132 | } |
128 | 133 | ||
134 | #[cfg(feature = "unix_stuff")] | ||
129 | impl Drop for JodChild { | 135 | impl Drop for JodChild { |
130 | fn drop(&mut self) { | 136 | fn drop(&mut self) { |
131 | let _ = self.0.kill(); | 137 | let _ = self.0.kill(); |
@@ -133,12 +139,10 @@ impl Drop for JodChild { | |||
133 | } | 139 | } |
134 | } | 140 | } |
135 | 141 | ||
142 | #[cfg(feature = "unix_stuff")] | ||
136 | impl JodChild { | 143 | impl JodChild { |
137 | pub fn into_inner(self) -> std::process::Child { | 144 | pub fn into_inner(self) -> std::process::Child { |
138 | if cfg!(target_arch = "wasm32") { | 145 | // SAFETY: repr transparent |
139 | panic!("no processes on wasm"); | ||
140 | } | ||
141 | // SAFETY: repr transparent, except on WASM | ||
142 | unsafe { std::mem::transmute::<JodChild, std::process::Child>(self) } | 146 | unsafe { std::mem::transmute::<JodChild, std::process::Child>(self) } |
143 | } | 147 | } |
144 | } | 148 | } |