Skip to content

Commit

Permalink
moved to ? operator instead of try!
Browse files Browse the repository at this point in the history
  • Loading branch information
alfanick committed Dec 22, 2016
1 parent fe75707 commit 2ce7ace
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub trait Calculator<T, P, E>
let evaluator = E::default();

let tokens = tokenizer.process(line);
let parsed_tokens = try!(parser.process(tokens));
let evaluated = try!(evaluator.process(parsed_tokens));
let parsed_tokens = parser.process(tokens)?;
let evaluated = evaluator.process(parsed_tokens)?;

Ok(evaluated)
}
Expand Down
6 changes: 3 additions & 3 deletions src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl TokensReducer for Evaluator {
match *token {
Token::Number(x) => stack.push(Polynomial::constant(x)),
Token::Operator(x) => {
let result = try!(self.call_function(&x.to_string(), position, &mut stack));
let result = self.call_function(&x.to_string(), position, &mut stack)?;
stack.push(result);
},
Token::Identifier(idx) => {
Expand All @@ -258,7 +258,7 @@ impl TokensReducer for Evaluator {
continue;
}

let result = try!(self.call_function(&x, position, &mut stack));
let result = self.call_function(&x, position, &mut stack)?;
stack.push(result);
},
_ => unreachable!()
Expand Down Expand Up @@ -556,7 +556,7 @@ mod tests {
evaluator.register_function("*", Function::new(2, Box::new(multiplication)));

evaluator.register_function("mod", Function::new(2, Box::new(|args|{
Ok(Polynomial::constant(try!(args[0].clone().as_f64()) % try!(args[1].clone().as_f64())))
Ok(Polynomial::constant(args[0].clone().as_f64()? % args[1].clone().as_f64()?))
})));

assert_eq!(evaluator.process(parser.process(tokenize_ref!("mod(17, 4)")).unwrap()), Ok(Polynomial::constant(1.0)));
Expand Down
6 changes: 3 additions & 3 deletions src/polynomial_calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub mod functions {
/// It will return a wrapped `PolynomialError::NonConstantError` when any of the
/// arguments is not a constant polynomial (a polynomial of degree zero).
pub fn log(args: Vec<Polynomial>) -> Result<Polynomial, EvaluationError> {
Ok(Polynomial::constant(try!(args[0].as_f64()).log(try!(args[1].as_f64()))))
Ok(Polynomial::constant(args[0].as_f64()?.log(args[1].as_f64()?)))
}

/// Computes a decimal logarithm (requires a single constant argument).
Expand All @@ -277,7 +277,7 @@ pub mod functions {
/// It will return a wrapped `PolynomialError::NonConstantError` when the argument
/// is not a constant polynomial (a polynomial of degree zero).
pub fn log10(args: Vec<Polynomial>) -> Result<Polynomial, EvaluationError> {
Ok(Polynomial::constant(try!(args[0].as_f64()).log10()))
Ok(Polynomial::constant(args[0].as_f64()?.log10()))
}

/// Binds a polynomial with a value (requires two arguments).
Expand All @@ -299,7 +299,7 @@ pub mod functions {
/// It will return a wrapped `PolynomialError::NonConstantError` when the second
/// argument is not a constant polynomial (a polynomial of degree zero).
pub fn bind(args: Vec<Polynomial>) -> Result<Polynomial, EvaluationError> {
Ok(args[0].bind(try!(args[1].as_f64())))
Ok(args[0].bind(args[1].as_f64()?))
}

/// Performs exponentiation of polynomial (requires two arguments).
Expand Down

0 comments on commit 2ce7ace

Please sign in to comment.