Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Set use_small_heuristics to Max in rustfmt.toml
Browse files Browse the repository at this point in the history
I set the `use_small_heuristics` rustfmt config option to `Max` since
it was formatting code to waste too much vertical space.
  • Loading branch information
SL-Lee committed Jan 15, 2022
1 parent 7e36aa6 commit a7b3916
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
edition = "2021"
use_small_heuristics = "Max"
4 changes: 1 addition & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ impl fmt::Display for Error {

impl From<num::ParseFloatError> for Error {
fn from(_: num::ParseFloatError) -> Self {
Error {
kind: ErrorKind::InvalidNumberInExpression,
}
Error { kind: ErrorKind::InvalidNumberInExpression }
}
}

Expand Down
20 changes: 7 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ pub mod error;
use crate::error::{Error, ErrorKind};

pub fn evaluate(expr_type: ExpressionType, expr: &str) -> Result<f64, Error> {
let mut tokens = expr
.split_ascii_whitespace()
.map(|slice| slice.to_string())
.collect::<Vec<String>>();
let mut tokens =
expr.split_ascii_whitespace().map(|slice| slice.to_string()).collect::<Vec<String>>();

if let ExpressionType::Prefix = expr_type {
tokens.reverse();
Expand All @@ -18,12 +16,10 @@ pub fn evaluate(expr_type: ExpressionType, expr: &str) -> Result<f64, Error> {
let token = tokens.remove(0);

if ["+", "-", "*", "/", "^"].contains(&token.as_str()) {
let mut right = stack
.pop()
.ok_or_else(|| Error::new(ErrorKind::InvalidInputExpression))?;
let mut left = stack
.pop()
.ok_or_else(|| Error::new(ErrorKind::InvalidInputExpression))?;
let mut right =
stack.pop().ok_or_else(|| Error::new(ErrorKind::InvalidInputExpression))?;
let mut left =
stack.pop().ok_or_else(|| Error::new(ErrorKind::InvalidInputExpression))?;

if let ExpressionType::Prefix = expr_type {
std::mem::swap(&mut left, &mut right);
Expand All @@ -46,9 +42,7 @@ pub fn evaluate(expr_type: ExpressionType, expr: &str) -> Result<f64, Error> {
}

if stack.len() == 1 {
stack
.pop()
.ok_or_else(|| Error::new(ErrorKind::InvalidInputExpression))
stack.pop().ok_or_else(|| Error::new(ErrorKind::InvalidInputExpression))
} else {
Err(Error::new(ErrorKind::InvalidInputExpression))
}
Expand Down

0 comments on commit a7b3916

Please sign in to comment.