aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-06-23 12:32:40 +0100
committerAkshay <[email protected]>2021-06-23 12:41:39 +0100
commitda1badf13b529a336d849cd73d4675fab17eec87 (patch)
tree1c57e785ca398bf0236f96beab367025b164405a
parent3381c2e4a8bcea2db3edd1741a7dd3fcdb15231b (diff)
feature flag unix specific stuffHEADmaster
-rw-r--r--crates/stdx/Cargo.toml2
-rw-r--r--crates/stdx/src/lib.rs14
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"
20winapi = "0.3.9" 20winapi = "0.3.9"
21 21
22[features] 22[features]
23default = []
24unix_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 @@
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}