Skip to content

Commit 27c2047

Browse files
authored
Merge pull request #8541 from cakebaker/who_refactor_if_else_chain
who: use `match` instead of `if`/`else` chain
2 parents 53c4bae + bc39c8a commit 27c2047

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/uu/who/src/platform/unix.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,20 @@ impl Who {
233233
if !self.my_line_only || cur_tty == ut.tty_device() {
234234
if self.need_users && ut.is_user_process() {
235235
self.print_user(&ut)?;
236-
} else if self.need_runlevel && run_level_chk(ut.record_type()) {
237-
if cfg!(target_os = "linux") {
238-
self.print_runlevel(&ut);
236+
} else {
237+
match ut.record_type() {
238+
rt if self.need_runlevel && run_level_chk(rt) => {
239+
if cfg!(target_os = "linux") {
240+
self.print_runlevel(&ut);
241+
}
242+
}
243+
utmpx::BOOT_TIME if self.need_boottime => self.print_boottime(&ut),
244+
utmpx::NEW_TIME if self.need_clockchange => self.print_clockchange(&ut),
245+
utmpx::INIT_PROCESS if self.need_initspawn => self.print_initspawn(&ut),
246+
utmpx::LOGIN_PROCESS if self.need_login => self.print_login(&ut),
247+
utmpx::DEAD_PROCESS if self.need_deadprocs => self.print_deadprocs(&ut),
248+
_ => {}
239249
}
240-
} else if self.need_boottime && ut.record_type() == utmpx::BOOT_TIME {
241-
self.print_boottime(&ut);
242-
} else if self.need_clockchange && ut.record_type() == utmpx::NEW_TIME {
243-
self.print_clockchange(&ut);
244-
} else if self.need_initspawn && ut.record_type() == utmpx::INIT_PROCESS {
245-
self.print_initspawn(&ut);
246-
} else if self.need_login && ut.record_type() == utmpx::LOGIN_PROCESS {
247-
self.print_login(&ut);
248-
} else if self.need_deadprocs && ut.record_type() == utmpx::DEAD_PROCESS {
249-
self.print_deadprocs(&ut);
250250
}
251251
}
252252

0 commit comments

Comments
 (0)