diff options
author | Akshay <[email protected]> | 2021-06-23 12:32:40 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-06-23 12:41:39 +0100 |
commit | da1badf13b529a336d849cd73d4675fab17eec87 (patch) | |
tree | 1c57e785ca398bf0236f96beab367025b164405a /crates/stdx/src | |
parent | 3381c2e4a8bcea2db3edd1741a7dd3fcdb15231b (diff) |
Diffstat (limited to 'crates/stdx/src')
-rw-r--r-- | crates/stdx/src/lib.rs | 14 |
1 files changed, 9 insertions, 5 deletions
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 | } |