Skip to content

Commit f1cf62e

Browse files
refactor: rename types to remove std/tokio name differentiation (#26)
Co-authored-by: Félix Saparelli <[email protected]>
1 parent 93b5dd2 commit f1cf62e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+420
-434
lines changed

src/generic_wrap.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
)]
55

66
macro_rules! Wrap {
7-
($name:ident, $command:ty, $wrapper:ident, $child:ty, $childer:ident, $first_child_wrapper:expr) => {
7+
($command:ty, $child:ty, $childer:ident, $first_child_wrapper:expr) => {
88
/// A wrapper around a `Command` that allows for additional functionality to be added.
99
///
1010
/// This is the core type of the `process-wrap` crate. It is a wrapper around a
1111
#[doc = concat!("[`", stringify!($command), "`].")]
1212
#[derive(Debug)]
13-
pub struct $name {
13+
pub struct CommandWrap {
1414
command: $command,
15-
wrappers: ::indexmap::IndexMap<::std::any::TypeId, Box<dyn $wrapper>>,
15+
wrappers: ::indexmap::IndexMap<::std::any::TypeId, Box<dyn CommandWrapper>>,
1616
}
1717

18-
impl $name {
18+
impl CommandWrap {
1919
/// Create from a program name and a closure to configure the command.
2020
///
2121
/// This is a convenience method that creates a new `Command` and then calls the closure
2222
/// to configure it. The `Command` is then wrapped and returned.
2323
///
24-
#[doc = concat!("Alternatively, use `From`/`Into` to convert a [`", stringify!($command),"`] to a [`", stringify!($name), "`].")]
24+
#[doc = concat!("Alternatively, use `From`/`Into` to convert a [`", stringify!($command),"`] to a [`", stringify!(CommandWrap), "`].")]
2525
pub fn with_new(
2626
program: impl AsRef<::std::ffi::OsStr>,
2727
init: impl FnOnce(&mut $command),
@@ -60,7 +60,7 @@ macro_rules! Wrap {
6060
/// will be silently discarded.
6161
///
6262
/// Returns `&mut self` for chaining.
63-
pub fn wrap<W: $wrapper + 'static>(&mut self, wrapper: W) -> &mut Self {
63+
pub fn wrap<W: CommandWrapper + 'static>(&mut self, wrapper: W) -> &mut Self {
6464
let typeid = ::std::any::TypeId::of::<W>();
6565
let mut wrapper = Some(Box::new(wrapper));
6666
let extant = self
@@ -79,7 +79,7 @@ macro_rules! Wrap {
7979
fn spawn_inner(
8080
&self,
8181
command: &mut $command,
82-
wrappers: &mut ::indexmap::IndexMap<::std::any::TypeId, Box<dyn $wrapper>>,
82+
wrappers: &mut ::indexmap::IndexMap<::std::any::TypeId, Box<dyn CommandWrapper>>,
8383
) -> ::std::io::Result<Box<dyn $childer>> {
8484
for (id, wrapper) in wrappers.iter_mut() {
8585
#[cfg(feature = "tracing")]
@@ -127,7 +127,7 @@ macro_rules! Wrap {
127127
}
128128

129129
/// Check if a wrapper of a given type is present.
130-
pub fn has_wrap<W: $wrapper + 'static>(&self) -> bool {
130+
pub fn has_wrap<W: CommandWrapper + 'static>(&self) -> bool {
131131
let typeid = ::std::any::TypeId::of::<W>();
132132
self.wrappers.contains_key(&typeid)
133133
}
@@ -139,7 +139,7 @@ macro_rules! Wrap {
139139
///
140140
/// Returns `None` if the wrapper is not present. To merely check if a wrapper is
141141
/// present, use `has_wrap` instead.
142-
pub fn get_wrap<W: $wrapper + 'static>(&self) -> Option<&W> {
142+
pub fn get_wrap<W: CommandWrapper + 'static>(&self) -> Option<&W> {
143143
let typeid = ::std::any::TypeId::of::<W>();
144144
self.wrappers.get(&typeid).map(|w| {
145145
let w_any = w as &dyn ::std::any::Any;
@@ -150,7 +150,7 @@ macro_rules! Wrap {
150150
}
151151
}
152152

153-
impl From<Command> for $name {
153+
impl From<Command> for CommandWrap {
154154
fn from(command: $command) -> Self {
155155
Self {
156156
command,
@@ -169,8 +169,8 @@ macro_rules! Wrap {
169169
/// ```rust,ignore
170170
/// #[derive(Debug)]
171171
/// pub struct YourWrapper;
172-
#[doc = concat!("impl ", stringify!($wrapper), " for YourWrapper {}\n```")]
173-
pub trait $wrapper: ::std::fmt::Debug + Send + Sync {
172+
#[doc = concat!("impl ", stringify!(CommandWrapper), " for YourWrapper {}\n```")]
173+
pub trait CommandWrapper: ::std::fmt::Debug + Send + Sync {
174174
/// Called on a first instance if a second of the same type is added.
175175
///
176176
/// Only one of a wrapper type can exist within a Wrap at a time. The default behaviour
@@ -184,7 +184,7 @@ macro_rules! Wrap {
184184
/// downcasting fails, instead of using unchecked downcasting and unleashing UB.
185185
///
186186
/// Default impl: no-op.
187-
fn extend(&mut self, _other: Box<dyn $wrapper>) {}
187+
fn extend(&mut self, _other: Box<dyn CommandWrapper>) {}
188188

189189
/// Called before the command is spawned, to mutate it as needed.
190190
///
@@ -194,7 +194,7 @@ macro_rules! Wrap {
194194
/// `CreationFlags` on Windows works along with `JobObject`.
195195
///
196196
/// Defaut impl: no-op.
197-
fn pre_spawn(&mut self, _command: &mut $command, _core: &$name) -> Result<()> {
197+
fn pre_spawn(&mut self, _command: &mut $command, _core: &CommandWrap) -> Result<()> {
198198
Ok(())
199199
}
200200

@@ -204,7 +204,7 @@ macro_rules! Wrap {
204204
/// how `CreationFlags` on Windows works along with `JobObject`.
205205
///
206206
/// Default: no-op.
207-
fn post_spawn(&mut self, _command: &mut $command, _child: &mut $child, _core: &$name) -> Result<()> {
207+
fn post_spawn(&mut self, _command: &mut $command, _child: &mut $child, _core: &CommandWrap) -> Result<()> {
208208
Ok(())
209209
}
210210

@@ -222,7 +222,7 @@ macro_rules! Wrap {
222222
fn wrap_child(
223223
&mut self,
224224
child: Box<dyn $childer>,
225-
_core: &$name,
225+
_core: &CommandWrap,
226226
) -> Result<Box<dyn $childer>> {
227227
Ok(child)
228228
}

0 commit comments

Comments
 (0)