Skip to content

Commit

Permalink
Merge pull request #11 from XDDudeGuy/Dev
Browse files Browse the repository at this point in the history
Merge Dev
  • Loading branch information
XDDudeGuy authored Oct 6, 2024
2 parents 93d8103 + a293b13 commit ca84aaf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/safe_operations.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
/// Has two variants Add and Multiply with no fields, used in the safe_math!() macro
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Operation {
Add,
Multiply
}

///Takes three expressions, two number inputs and one variant of the enum Operation. It combines the two numbers in whatever way was chosen or in the case of most errors evaluates to the Err variant with the field containing the larger of the two input numerical expressions
/// Allows conversion from bool to Operation and vice versa true means Add, false means Multiply
impl From<bool> for Operation {
fn from(value: bool) -> Self {
match value {
true => Operation::Add,
false => Operation::Multiply
}
}
}

/// Takes three expressions, two number inputs and one variant of the enum Operation. It combines the two numbers in whatever way was chosen or in the case of most errors evaluates to the Err variant with the field containing the larger of the two input numerical expressions
#[macro_export]
macro_rules! safe_math {
($in_x:expr, $in_y:expr, $operation:expr) => {
Expand Down

0 comments on commit ca84aaf

Please sign in to comment.