more idiomatic syntax
This commit is contained in:
parent
beb1ea7506
commit
634dff682b
@ -93,7 +93,7 @@ fn evaluate_node(ast_node: &AstNode) -> Result<Number, String> {
|
||||
let children = &ast_node.children;
|
||||
match token {
|
||||
Token::Number(number) => {
|
||||
Ok(Number::new(number.clone(), Unit::NoUnit))
|
||||
Ok(Number::new(*number, Unit::NoUnit))
|
||||
},
|
||||
Token::Constant(constant) => {
|
||||
match constant {
|
||||
@ -192,7 +192,7 @@ fn evaluate_node(ast_node: &AstNode) -> Result<Number, String> {
|
||||
Token::Unit(unit) => {
|
||||
let child_node = children.get(0).ok_or("Unit has no child[0]")?;
|
||||
let child_answer = evaluate_node(child_node)?;
|
||||
Ok(Number::new(child_answer.value, unit.clone()))
|
||||
Ok(Number::new(child_answer.value, *unit))
|
||||
},
|
||||
Token::Negative => {
|
||||
let child_node = children.get(0).ok_or("Negative has no child[0]")?;
|
||||
|
||||
@ -642,7 +642,7 @@ pub fn lex(input: &str, remove_trailing_operator: bool, default_degree: Unit) ->
|
||||
}
|
||||
|
||||
if tokens.is_empty() {
|
||||
Err("Input was empty".to_string())
|
||||
return Err("Input was empty".to_string());
|
||||
}
|
||||
|
||||
let mut token_index = 0;
|
||||
|
||||
@ -17,7 +17,7 @@ impl AstNode {
|
||||
pub fn new(token: Token) -> AstNode {
|
||||
AstNode {
|
||||
children: Vec::new(),
|
||||
token: token,
|
||||
token,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -494,7 +494,7 @@ pub fn to_ideal_joule_unit(number: Number) -> Number {
|
||||
/// - If you multiply [`ElectricCurrent`] with [`Resistance`], the result has a unit of [`Voltage`]
|
||||
/// - If you multiply [`Power`] with [`Time`], the result has a unit of [`Energy`]
|
||||
pub fn multiply(left: Number, right: Number) -> Result<Number, String> {
|
||||
Ok(actual_multiply(left, right, false)?)
|
||||
actual_multiply(left, right, false)
|
||||
}
|
||||
|
||||
fn actual_multiply(left: Number, right: Number, swapped: bool) -> Result<Number, String> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user