diff options
| author | Mattias Wallin <mattias.wallin@lidendata.com> | 2024-09-01 09:25:05 +0200 |
|---|---|---|
| committer | Yacin Tmimi <yacintmimi@gmail.com> | 2024-09-02 22:42:53 -0400 |
| commit | 5d30ce68441fabbf4e2b1c789b1af2327d9dc869 (patch) | |
| tree | 7954c9a1424f19c11264c52a5b1711c112e79391 | |
| parent | 9d407bfd1b69801d53c9c01dc8988f62d6235fed (diff) | |
| download | rust-5d30ce68441fabbf4e2b1c789b1af2327d9dc869.tar.gz rust-5d30ce68441fabbf4e2b1c789b1af2327d9dc869.zip | |
Avoid allocating intermediate strings in `determine_operation`
| -rw-r--r-- | src/bin/main.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs index 14299434bc7..3a0427d8372 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -462,16 +462,15 @@ fn print_version() { fn determine_operation(matches: &Matches) -> Result<Operation, OperationError> { if matches.opt_present("h") { - let topic = matches.opt_str("h"); - if topic.is_none() { + let Some(topic) = matches.opt_str("h") else { return Ok(Operation::Help(HelpOp::None)); - } else if topic == Some("config".to_owned()) { - return Ok(Operation::Help(HelpOp::Config)); - } else if topic == Some("file-lines".to_owned()) && is_nightly() { - return Ok(Operation::Help(HelpOp::FileLines)); - } else { - return Err(OperationError::UnknownHelpTopic(topic.unwrap())); - } + }; + + return match topic.as_str() { + "config" => Ok(Operation::Help(HelpOp::Config)), + "file-lines" if is_nightly() => Ok(Operation::Help(HelpOp::FileLines)), + _ => Err(OperationError::UnknownHelpTopic(topic)), + }; } let mut free_matches = matches.free.iter(); |
