Skip to content

Commit f3ef68f

Browse files
authored
feat: add strict clippy lints rules (#10)
I renamed `_spawn_and_stream` to `spawn_and_stream()` as an underscore in front of a method name typically indicates that a variable or function is not used. However, this is not the case here. For more info, see this clippy lint documentation: https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_items
1 parent 4199f5a commit f3ef68f

File tree

3 files changed

+70
-18
lines changed

3 files changed

+70
-18
lines changed

Cargo.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,38 @@ serde = { version = "1.0", features = ["derive"], optional = true }
2222
[features]
2323
default = []
2424
serde = ["dep:serde"]
25+
26+
[lints.clippy]
27+
all = "deny"
28+
pedantic = "deny"
29+
nursery = "deny"
30+
match_same_arms = { level = "allow", priority = 1 }
31+
32+
[lints.rust]
33+
# Groups
34+
warnings = "deny"
35+
future-incompatible = "deny"
36+
nonstandard-style = "deny"
37+
rust-2018-idioms = "deny"
38+
rust-2021-compatibility = "deny"
39+
rust-2024-compatibility = "deny"
40+
unused = "deny"
41+
42+
# Individual lints that deserve special attention
43+
invalid-html-tags = "deny"
44+
absolute-paths-not-starting-with-crate = "deny"
45+
anonymous-parameters = "deny"
46+
macro-use-extern-crate = "deny"
47+
missing-copy-implementations = "deny"
48+
missing-debug-implementations = "deny"
49+
missing-docs = "deny"
50+
semicolon-in-expressions-from-macros = "deny"
51+
unreachable-pub = "deny"
52+
variant-size-differences = "deny"
53+
unsafe-code = "deny"
54+
invalid-value = "deny"
55+
missing-abi = "deny"
56+
large-assignments = "deny"
57+
explicit-outlives-requirements = "deny"
58+
trivial-casts = "deny"
59+
trivial-numeric-casts = "deny"

src/item.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ impl Deref for ProcessItem {
1717

1818
fn deref(&self) -> &Self::Target {
1919
match self {
20-
ProcessItem::Output(s) => s,
21-
ProcessItem::Error(s) => s,
22-
ProcessItem::Exit(s) => s,
20+
Self::Output(s) => s,
21+
Self::Error(s) => s,
22+
Self::Exit(s) => s,
2323
}
2424
}
2525
}
@@ -54,23 +54,23 @@ impl ProcessItem {
5454
///
5555
/// [`Output`]: ProcessItem::Output
5656
#[must_use]
57-
pub fn is_output(&self) -> bool {
57+
pub const fn is_output(&self) -> bool {
5858
matches!(self, Self::Output(..))
5959
}
6060

6161
/// Returns `true` if the process item is [`Error`].
6262
///
6363
/// [`Error`]: ProcessItem::Error
6464
#[must_use]
65-
pub fn is_error(&self) -> bool {
65+
pub const fn is_error(&self) -> bool {
6666
matches!(self, Self::Error(..))
6767
}
6868

6969
/// Returns `true` if the process item is [`Exit`].
7070
///
7171
/// [`Exit`]: ProcessItem::Exit
7272
#[must_use]
73-
pub fn is_exit(&self) -> bool {
73+
pub const fn is_exit(&self) -> bool {
7474
matches!(self, Self::Exit(..))
7575
}
7676

@@ -83,7 +83,8 @@ impl ProcessItem {
8383
}
8484

8585
/// Return exit code if [`ProcessItem`] is [`ProcessItem::Exit`]
86-
pub fn as_exit(&self) -> Option<&String> {
86+
#[must_use]
87+
pub const fn as_exit(&self) -> Option<&String> {
8788
if let Self::Exit(v) = self {
8889
Some(v)
8990
} else {
@@ -92,7 +93,8 @@ impl ProcessItem {
9293
}
9394

9495
/// Return inner reference [`String`] value if [`ProcessItem`] is [`ProcessItem::Error`]
95-
pub fn as_error(&self) -> Option<&String> {
96+
#[must_use]
97+
pub const fn as_error(&self) -> Option<&String> {
9698
if let Self::Error(v) = self {
9799
Some(v)
98100
} else {
@@ -101,7 +103,8 @@ impl ProcessItem {
101103
}
102104

103105
/// Return inner reference [`String`] value if [`ProcessItem`] is [`ProcessItem::Output`]
104-
pub fn as_output(&self) -> Option<&String> {
106+
#[must_use]
107+
pub const fn as_output(&self) -> Option<&String> {
105108
if let Self::Output(v) = self {
106109
Some(v)
107110
} else {

src/lib.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use futures::TryStreamExt;
3636
pub use item::ProcessItem;
3737
pub use tokio_stream;
3838

39-
/// ProcessExt trait that needs to be implemented to make something streamable
39+
/// `ProcessExt` trait that needs to be implemented to make something streamable
4040
pub trait ProcessExt {
4141
/// Get command that will be used to create a child process from
4242
fn get_command(&mut self) -> &mut Command;
@@ -58,12 +58,25 @@ pub trait ProcessExt {
5858
}
5959

6060
/// Spawn and stream process
61+
///
62+
/// # Errors
63+
///
64+
/// Will return an error if the process fails to spawn
6165
fn spawn_and_stream(&mut self) -> Result<ProcessStream> {
62-
self._spawn_and_stream()
66+
self.spawn_and_stream_inner()
6367
}
6468

65-
/// Spawn and stream process (avoid custom implementation, use spawn_and_stream instead)
66-
fn _spawn_and_stream(&mut self) -> Result<ProcessStream> {
69+
/// # Errors
70+
///
71+
/// Will return an error if the process fails to spawn.
72+
///
73+
/// # Panics
74+
///
75+
/// Panics if:
76+
/// - `stdout` or `stderr` is not available in the spawned child process (should not happen if
77+
/// proper pipes are set up with `get_stdout()` and `get_stderr()`)
78+
#[allow(tail_expr_drop_order)]
79+
fn spawn_and_stream_inner(&mut self) -> Result<ProcessStream> {
6780
let abort = Arc::new(Notify::new());
6881

6982
let mut child = self.command().spawn()?;
@@ -79,7 +92,7 @@ pub trait ProcessExt {
7992
let mut std_stream = tokio_stream::StreamExt::merge(stdout_stream, stderr_stream);
8093
let stream = stream! {
8194
loop {
82-
use ProcessItem::*;
95+
use ProcessItem::{Error, Exit};
8396
tokio::select! {
8497
Some(output) = std_stream.next() => yield output,
8598
status = child.wait() => {
@@ -98,11 +111,11 @@ pub trait ProcessExt {
98111
}
99112
break;
100113
},
101-
_ = abort.notified() => {
114+
() = abort.notified() => {
102115
match child.start_kill() {
103116
Ok(()) => yield Exit("0".into()),
104117
Err(err) => yield Error(format!("abort Process Error: {err}")),
105-
};
118+
}
106119
break;
107120
}
108121
}
@@ -136,6 +149,7 @@ pub trait ProcessExt {
136149
}
137150

138151
/// Thin Wrapper around [`Command`] to make it streamable
152+
#[derive(Debug)]
139153
pub struct Process {
140154
inner: Command,
141155
stdin: Option<ChildStdin>,
@@ -155,7 +169,7 @@ impl ProcessExt for Process {
155169
}
156170

157171
fn set_aborter(&mut self, aborter: Option<Arc<Notify>>) {
158-
self.abort = aborter
172+
self.abort = aborter;
159173
}
160174

161175
fn take_stdin(&mut self) -> Option<ChildStdin> {
@@ -273,7 +287,7 @@ impl From<&PathBuf> for Process {
273287
}
274288
}
275289

276-
/// Convert std_stream to a stream of T
290+
/// Convert `std_stream` to a stream of T
277291
pub fn into_stream<T, R>(std: R, is_stdout: bool) -> impl Stream<Item = T>
278292
where
279293
T: From<(bool, Result<String>)>,

0 commit comments

Comments
 (0)