Skip to content

Commit 0193c1e

Browse files
committed
wip
1 parent e575ea6 commit 0193c1e

File tree

5 files changed

+89
-92
lines changed

5 files changed

+89
-92
lines changed

Diff for: src/blocking/command.rs

+29-30
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ impl Command {
2626
}
2727

2828
/// See [`std::process::Command::arg`]
29-
pub fn arg<S: AsRef<std::ffi::OsStr>>(&mut self, arg: S) -> &mut Self {
29+
#[must_use]
30+
pub fn arg<S: AsRef<std::ffi::OsStr>>(mut self, arg: S) -> Self {
3031
self.inner.arg(arg);
3132
self
3233
}
3334

3435
/// See [`std::process::Command::args`]
35-
pub fn args<I, S>(&mut self, args: I) -> &mut Self
36+
#[must_use]
37+
pub fn args<I, S>(mut self, args: I) -> Self
3638
where
3739
I: IntoIterator<Item = S>,
3840
S: AsRef<std::ffi::OsStr>,
@@ -42,7 +44,8 @@ impl Command {
4244
}
4345

4446
/// See [`std::process::Command::env`]
45-
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
47+
#[must_use]
48+
pub fn env<K, V>(mut self, key: K, val: V) -> Self
4649
where
4750
K: AsRef<std::ffi::OsStr>,
4851
V: AsRef<std::ffi::OsStr>,
@@ -52,7 +55,8 @@ impl Command {
5255
}
5356

5457
/// See [`std::process::Command::envs`]
55-
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
58+
#[must_use]
59+
pub fn envs<I, K, V>(mut self, vars: I) -> Self
5660
where
5761
I: IntoIterator<Item = (K, V)>,
5862
K: AsRef<std::ffi::OsStr>,
@@ -63,54 +67,45 @@ impl Command {
6367
}
6468

6569
/// See [`std::process::Command::env_remove`]
66-
pub fn env_remove<K: AsRef<std::ffi::OsStr>>(
67-
&mut self,
68-
key: K,
69-
) -> &mut Self {
70+
#[must_use]
71+
pub fn env_remove<K: AsRef<std::ffi::OsStr>>(mut self, key: K) -> Self {
7072
self.inner.env_remove(key);
7173
self
7274
}
7375

7476
/// See [`std::process::Command::env_clear`]
75-
pub fn env_clear(&mut self) -> &mut Self {
77+
#[must_use]
78+
pub fn env_clear(mut self) -> Self {
7679
self.inner.env_clear();
7780
self
7881
}
7982

8083
/// See [`std::process::Command::current_dir`]
81-
pub fn current_dir<P: AsRef<std::path::Path>>(
82-
&mut self,
83-
dir: P,
84-
) -> &mut Self {
84+
#[must_use]
85+
pub fn current_dir<P: AsRef<std::path::Path>>(mut self, dir: P) -> Self {
8586
self.inner.current_dir(dir);
8687
self
8788
}
8889

8990
/// See [`std::process::Command::stdin`]
90-
pub fn stdin<T: Into<std::process::Stdio>>(
91-
&mut self,
92-
cfg: T,
93-
) -> &mut Self {
91+
#[must_use]
92+
pub fn stdin<T: Into<std::process::Stdio>>(mut self, cfg: T) -> Self {
9493
self.stdin = true;
9594
self.inner.stdin(cfg);
9695
self
9796
}
9897

9998
/// See [`std::process::Command::stdout`]
100-
pub fn stdout<T: Into<std::process::Stdio>>(
101-
&mut self,
102-
cfg: T,
103-
) -> &mut Self {
99+
#[must_use]
100+
pub fn stdout<T: Into<std::process::Stdio>>(mut self, cfg: T) -> Self {
104101
self.stdout = true;
105102
self.inner.stdout(cfg);
106103
self
107104
}
108105

109106
/// See [`std::process::Command::stderr`]
110-
pub fn stderr<T: Into<std::process::Stdio>>(
111-
&mut self,
112-
cfg: T,
113-
) -> &mut Self {
107+
#[must_use]
108+
pub fn stderr<T: Into<std::process::Stdio>>(mut self, cfg: T) -> Self {
114109
self.stderr = true;
115110
self.inner.stderr(cfg);
116111
self
@@ -133,7 +128,7 @@ impl Command {
133128
/// session leader or set its controlling terminal.
134129
#[allow(clippy::needless_pass_by_value)]
135130
pub fn spawn(
136-
&mut self,
131+
mut self,
137132
pts: crate::blocking::Pts,
138133
) -> crate::Result<std::process::Child> {
139134
self.spawn_impl(&pts)
@@ -202,20 +197,23 @@ impl Command {
202197
}
203198

204199
/// See [`std::os::unix::process::CommandExt::uid`]
205-
pub fn uid(&mut self, id: u32) -> &mut Self {
200+
#[must_use]
201+
pub fn uid(mut self, id: u32) -> Self {
206202
self.inner.uid(id);
207203
self
208204
}
209205

210206
/// See [`std::os::unix::process::CommandExt::gid`]
211-
pub fn gid(&mut self, id: u32) -> &mut Self {
207+
#[must_use]
208+
pub fn gid(mut self, id: u32) -> Self {
212209
self.inner.gid(id);
213210
self
214211
}
215212

216213
/// See [`std::os::unix::process::CommandExt::pre_exec`]
217214
#[allow(clippy::missing_safety_doc)]
218-
pub unsafe fn pre_exec<F>(&mut self, f: F) -> &mut Self
215+
#[must_use]
216+
pub unsafe fn pre_exec<F>(mut self, f: F) -> Self
219217
where
220218
F: FnMut() -> std::io::Result<()> + Send + Sync + 'static,
221219
{
@@ -224,7 +222,8 @@ impl Command {
224222
}
225223

226224
/// See [`std::os::unix::process::CommandExt::arg0`]
227-
pub fn arg0<S>(&mut self, arg: S) -> &mut Self
225+
#[must_use]
226+
pub fn arg0<S>(mut self, arg: S) -> Self
228227
where
229228
S: AsRef<std::ffi::OsStr>,
230229
{

Diff for: src/command.rs

+31-31
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ impl Command {
2424
}
2525

2626
/// See [`tokio::process::Command::arg`]
27-
pub fn arg<S: AsRef<std::ffi::OsStr>>(&mut self, arg: S) -> &mut Self {
27+
#[must_use]
28+
pub fn arg<S: AsRef<std::ffi::OsStr>>(mut self, arg: S) -> Self {
2829
self.inner.arg(arg);
2930
self
3031
}
3132

3233
/// See [`tokio::process::Command::args`]
33-
pub fn args<I, S>(&mut self, args: I) -> &mut Self
34+
#[must_use]
35+
pub fn args<I, S>(mut self, args: I) -> Self
3436
where
3537
I: IntoIterator<Item = S>,
3638
S: AsRef<std::ffi::OsStr>,
@@ -40,7 +42,8 @@ impl Command {
4042
}
4143

4244
/// See [`tokio::process::Command::env`]
43-
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
45+
#[must_use]
46+
pub fn env<K, V>(mut self, key: K, val: V) -> Self
4447
where
4548
K: AsRef<std::ffi::OsStr>,
4649
V: AsRef<std::ffi::OsStr>,
@@ -50,7 +53,8 @@ impl Command {
5053
}
5154

5255
/// See [`tokio::process::Command::envs`]
53-
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Self
56+
#[must_use]
57+
pub fn envs<I, K, V>(mut self, vars: I) -> Self
5458
where
5559
I: IntoIterator<Item = (K, V)>,
5660
K: AsRef<std::ffi::OsStr>,
@@ -61,60 +65,52 @@ impl Command {
6165
}
6266

6367
/// See [`tokio::process::Command::env_remove`]
64-
pub fn env_remove<K: AsRef<std::ffi::OsStr>>(
65-
&mut self,
66-
key: K,
67-
) -> &mut Self {
68+
#[must_use]
69+
pub fn env_remove<K: AsRef<std::ffi::OsStr>>(mut self, key: K) -> Self {
6870
self.inner.env_remove(key);
6971
self
7072
}
7173

7274
/// See [`tokio::process::Command::env_clear`]
73-
pub fn env_clear(&mut self) -> &mut Self {
75+
#[must_use]
76+
pub fn env_clear(mut self) -> Self {
7477
self.inner.env_clear();
7578
self
7679
}
7780

7881
/// See [`tokio::process::Command::current_dir`]
79-
pub fn current_dir<P: AsRef<std::path::Path>>(
80-
&mut self,
81-
dir: P,
82-
) -> &mut Self {
82+
#[must_use]
83+
pub fn current_dir<P: AsRef<std::path::Path>>(mut self, dir: P) -> Self {
8384
self.inner.current_dir(dir);
8485
self
8586
}
8687

8788
/// See [`tokio::process::Command::kill_on_drop`]
88-
pub fn kill_on_drop(&mut self, kill_on_drop: bool) -> &mut Self {
89+
#[must_use]
90+
pub fn kill_on_drop(mut self, kill_on_drop: bool) -> Self {
8991
self.inner.kill_on_drop(kill_on_drop);
9092
self
9193
}
9294

9395
/// See [`tokio::process::Command::stdin`]
94-
pub fn stdin<T: Into<std::process::Stdio>>(
95-
&mut self,
96-
cfg: T,
97-
) -> &mut Self {
96+
#[must_use]
97+
pub fn stdin<T: Into<std::process::Stdio>>(mut self, cfg: T) -> Self {
9898
self.stdin = true;
9999
self.inner.stdin(cfg);
100100
self
101101
}
102102

103103
/// See [`tokio::process::Command::stdout`]
104-
pub fn stdout<T: Into<std::process::Stdio>>(
105-
&mut self,
106-
cfg: T,
107-
) -> &mut Self {
104+
#[must_use]
105+
pub fn stdout<T: Into<std::process::Stdio>>(mut self, cfg: T) -> Self {
108106
self.stdout = true;
109107
self.inner.stdout(cfg);
110108
self
111109
}
112110

113111
/// See [`tokio::process::Command::stderr`]
114-
pub fn stderr<T: Into<std::process::Stdio>>(
115-
&mut self,
116-
cfg: T,
117-
) -> &mut Self {
112+
#[must_use]
113+
pub fn stderr<T: Into<std::process::Stdio>>(mut self, cfg: T) -> Self {
118114
self.stderr = true;
119115
self.inner.stderr(cfg);
120116
self
@@ -137,7 +133,7 @@ impl Command {
137133
/// session leader or set its controlling terminal.
138134
#[allow(clippy::needless_pass_by_value)]
139135
pub fn spawn(
140-
&mut self,
136+
mut self,
141137
pts: crate::Pts,
142138
) -> crate::Result<tokio::process::Child> {
143139
self.spawn_impl(&pts)
@@ -206,20 +202,23 @@ impl Command {
206202
}
207203

208204
/// See [`tokio::process::Command::uid`]
209-
pub fn uid(&mut self, id: u32) -> &mut Self {
205+
#[must_use]
206+
pub fn uid(mut self, id: u32) -> Self {
210207
self.inner.uid(id);
211208
self
212209
}
213210

214211
/// See [`tokio::process::Command::gid`]
215-
pub fn gid(&mut self, id: u32) -> &mut Self {
212+
#[must_use]
213+
pub fn gid(mut self, id: u32) -> Self {
216214
self.inner.gid(id);
217215
self
218216
}
219217

220218
/// See [`tokio::process::Command::pre_exec`]
221219
#[allow(clippy::missing_safety_doc)]
222-
pub unsafe fn pre_exec<F>(&mut self, f: F) -> &mut Self
220+
#[must_use]
221+
pub unsafe fn pre_exec<F>(mut self, f: F) -> Self
223222
where
224223
F: FnMut() -> std::io::Result<()> + Send + Sync + 'static,
225224
{
@@ -228,7 +227,8 @@ impl Command {
228227
}
229228

230229
/// See [`tokio::process::Command::arg0`]
231-
pub fn arg0<S>(&mut self, arg: S) -> &mut Self
230+
#[must_use]
231+
pub fn arg0<S>(mut self, arg: S) -> Self
232232
where
233233
S: AsRef<std::ffi::OsStr>,
234234
{

Diff for: tests/behavior.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,19 @@ fn test_multiple_configured() {
7575
let (pre_exec_pipe_r, pre_exec_pipe_w) = pipe();
7676
let mut pre_exec_pipe_r =
7777
std::io::BufReader::new(std::fs::File::from(pre_exec_pipe_r));
78-
let mut cmd = pty_process::blocking::Command::new("perl");
79-
cmd.arg("-Esay 'foo'; say STDERR 'foo-stderr'; open my $fh, '>&=3'; say $fh 'foo-3';")
78+
let cmd = pty_process::blocking::Command::new("perl")
79+
.arg("-Esay 'foo'; say STDERR 'foo-stderr'; open my $fh, '>&=3'; say $fh 'foo-3';")
8080
.stderr(std::process::Stdio::from(stderr_pipe_w));
81-
unsafe {
81+
let mut cmd = unsafe {
8282
cmd.pre_exec(move || {
8383
nix::unistd::dup2(pre_exec_pipe_w.as_raw_fd(), 3)?;
8484
nix::fcntl::fcntl(
8585
3,
8686
nix::fcntl::F_SETFD(nix::fcntl::FdFlag::empty()),
8787
)?;
8888
Ok(())
89-
});
90-
}
89+
})
90+
};
9191
let mut child = cmd.spawn_borrowed(&pts).unwrap();
9292

9393
let mut output = helpers::output(&pty);
@@ -149,24 +149,24 @@ async fn test_multiple_configured_async() {
149149
let mut pre_exec_pipe_r = tokio::io::BufReader::new(unsafe {
150150
tokio::fs::File::from_raw_fd(pre_exec_pipe_r.into_raw_fd())
151151
});
152-
let mut cmd = pty_process::Command::new("perl");
153-
cmd.arg(
154-
"-Esay 'foo'; \
152+
let cmd = pty_process::Command::new("perl")
153+
.arg(
154+
"-Esay 'foo'; \
155155
say STDERR 'foo-stderr'; \
156156
open my $fh, '>&=3'; \
157157
say $fh 'foo-3';",
158-
)
159-
.stderr(std::process::Stdio::from(stderr_pipe_w));
160-
unsafe {
158+
)
159+
.stderr(std::process::Stdio::from(stderr_pipe_w));
160+
let mut cmd = unsafe {
161161
cmd.pre_exec(move || {
162162
nix::unistd::dup2(pre_exec_pipe_w.as_raw_fd(), 3)?;
163163
nix::fcntl::fcntl(
164164
3,
165165
nix::fcntl::F_SETFD(nix::fcntl::FdFlag::empty()),
166166
)?;
167167
Ok(())
168-
});
169-
}
168+
})
169+
};
170170
let mut child = cmd.spawn_borrowed(&pts).unwrap();
171171

172172
let mut output = helpers::output_async(pty_r);

0 commit comments

Comments
 (0)