Skip to content

Commit 922c64a

Browse files
committed
style: Make clippy happy
1 parent b4a4e13 commit 922c64a

File tree

8 files changed

+67
-69
lines changed

8 files changed

+67
-69
lines changed

examples/bash_read.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() -> Result<(), Error> {
88
p.send_line("hostname")?;
99
let hostname = p.read_line()?;
1010
p.wait_for_prompt()?; // go sure `hostname` is really done
11-
println!("Current hostname: {}", hostname);
11+
println!("Current hostname: {hostname}");
1212

1313
// case 2: wait until done, only extract a few infos
1414
p.send_line("wc /etc/passwd")?;
@@ -17,17 +17,14 @@ fn main() -> Result<(), Error> {
1717
let (_, words) = p.exp_regex("[0-9]+")?;
1818
let (_, bytes) = p.exp_regex("[0-9]+")?;
1919
p.wait_for_prompt()?; // go sure `wc` is really done
20-
println!(
21-
"/etc/passwd has {} lines, {} words, {} chars",
22-
lines, words, bytes
23-
);
20+
println!("/etc/passwd has {lines} lines, {words} words, {bytes} chars");
2421

2522
// case 3: read while program is still executing
2623
p.execute("ping 8.8.8.8", "bytes of data")?; // returns when it sees "bytes of data" in output
2724
for _ in 0..5 {
2825
// times out if one ping takes longer than 2s
2926
let (_, duration) = p.exp_regex("[0-9. ]+ ms")?;
30-
println!("Roundtrip time: {}", duration);
27+
println!("Roundtrip time: {duration}");
3128
}
3229
p.send_control('c')?;
3330
Ok(())

examples/exit_code.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() -> Result<(), Error> {
1717
match p.process.wait() {
1818
Ok(wait::WaitStatus::Exited(_, 0)) => println!("cat succeeded"),
1919
Ok(wait::WaitStatus::Exited(_, c)) => {
20-
println!("Cat failed with exit code {}", c);
20+
println!("Cat failed with exit code {c}");
2121
println!("Output (stdout and stderr): {}", p.exp_eof()?);
2222
}
2323
// for other possible return types of wait()

examples/repl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ fn ed_session() -> Result<PtyReplSession, Error> {
1111
echo_on: false,
1212

1313
// used for `wait_for_prompt()`
14-
prompt: "> ".to_string(),
14+
prompt: "> ".to_owned(),
1515
pty_session: spawn("/bin/ed -p '> '", Some(2000))?,
1616
// command which is sent when the instance of this struct is dropped
1717
// in the below example this is not needed, but if you don't explicitly
1818
// exit a REPL then rexpect tries to send a SIGTERM and depending on the repl
1919
// this does not end the repl and would end up in an error
20-
quit_command: Some("Q".to_string()),
20+
quit_command: Some("Q".to_owned()),
2121
};
2222
ed.wait_for_prompt()?;
2323
Ok(ed)

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time;
22

33
#[derive(Debug, thiserror::Error)]
44
pub enum Error {
5-
#[error("EOF (End of File): Expected {} but got EOF after reading \"{}\" process terminated with {:?}", .expected, .got, .exit_code.as_ref().unwrap_or(&"unknown".to_string()))]
5+
#[error("EOF (End of File): Expected {} but got EOF after reading \"{}\" process terminated with {:?}", .expected, .got, .exit_code.as_ref().unwrap_or(&"unknown".to_owned()))]
66
EOF {
77
expected: String,
88
got: String,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
//! # Example with bash
4040
//!
4141
//! Tip: try the chain of commands first in a bash session.
42-
//! The tricky thing is to get the wait_for_prompt right.
42+
//! The tricky thing is to get the `wait_for_prompt` right.
4343
//! What `wait_for_prompt` actually does is seeking to the next
4444
//! visible prompt. If you forgot to call this once your next call to
4545
//! `wait_for_prompt` comes out of sync and you're seeking to a prompt

src/process.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::{thread, time};
1919
/// Start a process in a forked tty so you can interact with it the same as you would
2020
/// within a terminal
2121
///
22-
/// The process and pty session are killed upon dropping PtyProcess
22+
/// The process and pty session are killed upon dropping `PtyProcess`
2323
///
2424
/// # Example
2525
///
@@ -142,8 +142,8 @@ impl PtyProcess {
142142
unsafe { Ok(File::from_raw_fd(fd)) }
143143
}
144144

145-
/// At the drop of PtyProcess the running process is killed. This is blocking forever if
146-
/// the process does not react to a normal kill. If kill_timeout is set the process is
145+
/// At the drop of `PtyProcess` the running process is killed. This is blocking forever if
146+
/// the process does not react to a normal kill. If `kill_timeout` is set the process is
147147
/// `kill -9`ed after duration
148148
pub fn set_kill_timeout(&mut self, timeout_ms: Option<u64>) {
149149
self.kill_timeout = timeout_ms.map(time::Duration::from_millis);
@@ -197,7 +197,7 @@ impl PtyProcess {
197197
/// Kill the process with a specific signal. This method blocks, until the process is dead
198198
///
199199
/// repeatedly sends SIGTERM to the process until it died,
200-
/// the pty session is closed upon dropping PtyMaster,
200+
/// the pty session is closed upon dropping `PtyMaster`,
201201
/// so we don't need to explicitly do that here.
202202
///
203203
/// if `kill_timeout` is set and a repeated sending of signal does not result in the process
@@ -221,7 +221,7 @@ impl PtyProcess {
221221
// kill -9 if timout is reached
222222
if let Some(timeout) = self.kill_timeout {
223223
if start.elapsed() > timeout {
224-
signal::kill(self.child_pid, signal::Signal::SIGKILL).map_err(Error::from)?
224+
signal::kill(self.child_pid, signal::Signal::SIGKILL).map_err(Error::from)?;
225225
}
226226
}
227227
}
@@ -244,7 +244,7 @@ mod tests {
244244

245245
#[test]
246246
/// Open cat, write string, read back string twice, send Ctrl^C and check that cat exited
247-
fn test_cat() -> std::io::Result<()> {
247+
fn test_cat() -> io::Result<()> {
248248
let process = PtyProcess::new(Command::new("cat")).expect("could not execute cat");
249249
let f = process.get_file_handle().unwrap();
250250
let mut writer = LineWriter::new(&f);

src/reader.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ pub use regex::Regex;
55
use std::io::prelude::*;
66
use std::io::{self, BufReader};
77
use std::sync::mpsc::{channel, Receiver};
8+
use std::thread;
89
use std::{fmt, time};
9-
use std::{result, thread};
1010

1111
#[derive(Debug)]
1212
enum PipeError {
@@ -29,14 +29,14 @@ pub enum ReadUntil {
2929
}
3030

3131
impl fmt::Display for ReadUntil {
32-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3333
let printable = match self {
34-
ReadUntil::String(ref s) if s == "\n" => "\\n (newline)".to_string(),
35-
ReadUntil::String(ref s) if s == "\r" => "\\r (carriage return)".to_string(),
36-
ReadUntil::String(ref s) => format!("\"{}\"", s),
37-
ReadUntil::Regex(ref r) => format!("Regex: \"{}\"", r),
38-
ReadUntil::EOF => "EOF (End of File)".to_string(),
39-
ReadUntil::NBytes(n) => format!("reading {} bytes", n),
34+
ReadUntil::String(ref s) if s == "\n" => "\\n (newline)".to_owned(),
35+
ReadUntil::String(ref s) if s == "\r" => "\\r (carriage return)".to_owned(),
36+
ReadUntil::String(ref s) => format!("\"{s}\""),
37+
ReadUntil::Regex(ref r) => format!("Regex: \"{r}\""),
38+
ReadUntil::EOF => "EOF (End of File)".to_owned(),
39+
ReadUntil::NBytes(n) => format!("reading {n} bytes"),
4040
ReadUntil::Any(ref v) => {
4141
let mut res = Vec::new();
4242
for r in v {
@@ -45,7 +45,7 @@ impl fmt::Display for ReadUntil {
4545
res.join(", ")
4646
}
4747
};
48-
write!(f, "{}", printable)
48+
write!(f, "{printable}")
4949
}
5050
}
5151

@@ -98,12 +98,12 @@ pub fn find(needle: &ReadUntil, buffer: &str, eof: bool) -> Option<(usize, usize
9898
}
9999
}
100100

101-
/// Options for NBReader
101+
/// Options for `NBReader`
102102
///
103103
/// - timeout:
104-
/// + `None`: read_until is blocking forever. This is probably not what you want
104+
/// + `None`: `read_until` is blocking forever. This is probably not what you want
105105
/// + `Some(millis)`: after millis milliseconds a timeout error is raised
106-
/// - strip_ansi_escape_codes: Whether to filter out escape codes, such as colors.
106+
/// - `strip_ansi_escape_codes`: Whether to filter out escape codes, such as colors.
107107
#[derive(Default)]
108108
pub struct Options {
109109
pub timeout_ms: Option<u64>,
@@ -116,7 +116,7 @@ pub struct Options {
116116
/// Internally a thread is spawned and the output is read ahead so when
117117
/// calling `read_line` or `read_until` it reads from an internal buffer
118118
pub struct NBReader {
119-
reader: Receiver<result::Result<PipedChar, PipeError>>,
119+
reader: Receiver<Result<PipedChar, PipeError>>,
120120
buffer: String,
121121
eof: bool,
122122
timeout: Option<time::Duration>,
@@ -192,7 +192,7 @@ impl NBReader {
192192
Err(PipeError::IO(ref err)) => {
193193
// For an explanation of why we use `raw_os_error` see:
194194
// https://github.com/zhiburt/ptyprocess/commit/df003c8e3ff326f7d17bc723bc7c27c50495bb62
195-
self.eof = err.raw_os_error() == Some(5)
195+
self.eof = err.raw_os_error() == Some(5);
196196
}
197197
}
198198
}
@@ -207,7 +207,7 @@ impl NBReader {
207207
///
208208
/// There are different modes:
209209
///
210-
/// - `ReadUntil::String` searches for string (use '\n'.to_string() to search for newline).
210+
/// - `ReadUntil::String` searches for string (use '\n'.`to_string()` to search for newline).
211211
/// Returns not yet read data in first String, and needle in second String
212212
/// - `ReadUntil::Regex` searches for regex
213213
/// Returns not yet read data in first String and matched regex in second String
@@ -310,8 +310,8 @@ mod tests {
310310
let f = io::Cursor::new("a melon\r\n");
311311
let mut r = NBReader::new(f, Options::default());
312312
assert_eq!(
313-
("a melon".to_string(), "\r\n".to_string()),
314-
r.read_until(&ReadUntil::String("\r\n".to_string()))
313+
("a melon".to_owned(), "\r\n".to_owned()),
314+
r.read_until(&ReadUntil::String("\r\n".to_owned()))
315315
.expect("cannot read line")
316316
);
317317
// check for EOF
@@ -328,7 +328,7 @@ mod tests {
328328
let mut r = NBReader::new(f, Options::default());
329329
let re = Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
330330
assert_eq!(
331-
("".to_string(), "2014-03-15".to_string()),
331+
("".to_owned(), "2014-03-15".to_owned()),
332332
r.read_until(&ReadUntil::Regex(re))
333333
.expect("regex doesn't match")
334334
);
@@ -340,7 +340,7 @@ mod tests {
340340
let mut r = NBReader::new(f, Options::default());
341341
let re = Regex::new(r"-\d{2}-").unwrap();
342342
assert_eq!(
343-
("2014".to_string(), "-03-".to_string()),
343+
("2014".to_owned(), "-03-".to_owned()),
344344
r.read_until(&ReadUntil::Regex(re))
345345
.expect("regex doesn't match")
346346
);
@@ -351,15 +351,15 @@ mod tests {
351351
let f = io::Cursor::new("abcdef");
352352
let mut r = NBReader::new(f, Options::default());
353353
assert_eq!(
354-
("".to_string(), "ab".to_string()),
354+
("".to_owned(), "ab".to_owned()),
355355
r.read_until(&ReadUntil::NBytes(2)).expect("2 bytes")
356356
);
357357
assert_eq!(
358-
("".to_string(), "cde".to_string()),
358+
("".to_owned(), "cde".to_owned()),
359359
r.read_until(&ReadUntil::NBytes(3)).expect("3 bytes")
360360
);
361361
assert_eq!(
362-
("".to_string(), "f".to_string()),
362+
("".to_owned(), "f".to_owned()),
363363
r.read_until(&ReadUntil::NBytes(4)).expect("4 bytes")
364364
);
365365
}
@@ -371,12 +371,12 @@ mod tests {
371371

372372
let result = r
373373
.read_until(&ReadUntil::Any(vec![
374-
ReadUntil::String("two".to_string()),
375-
ReadUntil::String("one".to_string()),
374+
ReadUntil::String("two".to_owned()),
375+
ReadUntil::String("one".to_owned()),
376376
]))
377377
.expect("finding string");
378378

379-
assert_eq!(("zero ".to_string(), "one".to_string()), result);
379+
assert_eq!(("zero ".to_owned(), "one".to_owned()), result);
380380
}
381381

382382
#[test]
@@ -386,12 +386,12 @@ mod tests {
386386

387387
let result = r
388388
.read_until(&ReadUntil::Any(vec![
389-
ReadUntil::String("hello".to_string()),
390-
ReadUntil::String("hell".to_string()),
389+
ReadUntil::String("hello".to_owned()),
390+
ReadUntil::String("hell".to_owned()),
391391
]))
392392
.expect("finding string");
393393

394-
assert_eq!(("hi ".to_string(), "hell".to_string()), result);
394+
assert_eq!(("hi ".to_owned(), "hell".to_owned()), result);
395395
}
396396

397397
#[test]
@@ -400,7 +400,7 @@ mod tests {
400400
let mut r = NBReader::new(f, Options::default());
401401
r.read_until(&ReadUntil::NBytes(2)).expect("2 bytes");
402402
assert_eq!(
403-
("".to_string(), "rem ipsum dolor sit amet".to_string()),
403+
("".to_owned(), "rem ipsum dolor sit amet".to_owned()),
404404
r.read_until(&ReadUntil::EOF).expect("reading until EOF")
405405
);
406406
}
@@ -416,9 +416,9 @@ mod tests {
416416
},
417417
);
418418
let bytes = r
419-
.read_until(&ReadUntil::String("Hello".to_string()))
419+
.read_until(&ReadUntil::String("Hello".to_owned()))
420420
.unwrap();
421-
assert_eq!(bytes, ("".to_string(), "Hello".to_string()));
421+
assert_eq!(bytes, ("".to_owned(), "Hello".to_owned()));
422422
assert_eq!(None, r.try_read());
423423
}
424424

@@ -433,9 +433,9 @@ mod tests {
433433
},
434434
);
435435
let bytes = r
436-
.read_until(&ReadUntil::String("Hello".to_string()))
436+
.read_until(&ReadUntil::String("Hello".to_owned()))
437437
.unwrap();
438-
assert_eq!(bytes, ("".to_string(), "Hello".to_string()));
438+
assert_eq!(bytes, ("".to_owned(), "Hello".to_owned()));
439439
assert_eq!(None, r.try_read());
440440
}
441441

0 commit comments

Comments
 (0)