aboutsummaryrefslogtreecommitdiff
path: root/crates/stdx/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/stdx/src')
-rw-r--r--crates/stdx/src/lib.rs14
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 @@
2use std::{cmp::Ordering, ops, time::Instant}; 2use std::{cmp::Ordering, ops, time::Instant};
3 3
4mod macros; 4mod macros;
5#[cfg(feature = "unix_stuff")]
5pub mod process; 6pub mod process;
6pub mod panic_context; 7pub 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)]
114pub struct JodChild(pub std::process::Child); 117pub struct JodChild(pub std::process::Child);
115 118
119#[cfg(feature = "unix_stuff")]
116impl ops::Deref for JodChild { 120impl 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")]
123impl ops::DerefMut for JodChild { 128impl 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")]
129impl Drop for JodChild { 135impl 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")]
136impl JodChild { 143impl 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}