Skip to content

Commit c853e31

Browse files
committed
Add #[must_use] attribute to several command-related methods
This should make it harder to accidentally forget to use results of methods on `BootstrapCommand` and `CommandStatus`.
1 parent f933d78 commit c853e31

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/bootstrap/src/utils/exec.rs

+14
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ impl BootstrapCommand {
9191
self
9292
}
9393

94+
#[must_use]
9495
pub fn get_envs(&self) -> CommandEnvs<'_> {
9596
self.command.get_envs()
9697
}
9798

99+
#[must_use]
98100
pub fn get_args(&self) -> CommandArgs<'_> {
99101
self.command.get_args()
100102
}
@@ -109,14 +111,17 @@ impl BootstrapCommand {
109111
self
110112
}
111113

114+
#[must_use]
112115
pub fn delay_failure(self) -> Self {
113116
Self { failure_behavior: BehaviorOnFailure::DelayFail, ..self }
114117
}
115118

119+
#[must_use]
116120
pub fn fail_fast(self) -> Self {
117121
Self { failure_behavior: BehaviorOnFailure::Exit, ..self }
118122
}
119123

124+
#[must_use]
120125
pub fn allow_failure(self) -> Self {
121126
Self { failure_behavior: BehaviorOnFailure::Ignore, ..self }
122127
}
@@ -127,11 +132,13 @@ impl BootstrapCommand {
127132
}
128133

129134
/// Capture all output of the command, do not print it.
135+
#[must_use]
130136
pub fn capture(self) -> Self {
131137
Self { stdout: OutputMode::Capture, stderr: OutputMode::Capture, ..self }
132138
}
133139

134140
/// Capture stdout of the command, do not print it.
141+
#[must_use]
135142
pub fn capture_stdout(self) -> Self {
136143
Self { stdout: OutputMode::Capture, ..self }
137144
}
@@ -178,36 +185,43 @@ pub struct CommandOutput {
178185
}
179186

180187
impl CommandOutput {
188+
#[must_use]
181189
pub fn did_not_start() -> Self {
182190
Self { status: CommandStatus::DidNotStart, stdout: vec![], stderr: vec![] }
183191
}
184192

193+
#[must_use]
185194
pub fn is_success(&self) -> bool {
186195
match self.status {
187196
CommandStatus::Finished(status) => status.success(),
188197
CommandStatus::DidNotStart => false,
189198
}
190199
}
191200

201+
#[must_use]
192202
pub fn is_failure(&self) -> bool {
193203
!self.is_success()
194204
}
195205

206+
#[must_use]
196207
pub fn status(&self) -> Option<ExitStatus> {
197208
match self.status {
198209
CommandStatus::Finished(status) => Some(status),
199210
CommandStatus::DidNotStart => None,
200211
}
201212
}
202213

214+
#[must_use]
203215
pub fn stdout(&self) -> String {
204216
String::from_utf8(self.stdout.clone()).expect("Cannot parse process stdout as UTF-8")
205217
}
206218

219+
#[must_use]
207220
pub fn stdout_if_ok(&self) -> Option<String> {
208221
if self.is_success() { Some(self.stdout()) } else { None }
209222
}
210223

224+
#[must_use]
211225
pub fn stderr(&self) -> String {
212226
String::from_utf8(self.stderr.clone()).expect("Cannot parse process stderr as UTF-8")
213227
}

0 commit comments

Comments
 (0)