pub enum Operation {
Add,
Subtract,
Multiply,
Divide,
}Expand description
Arithmetic operations that can be applied in routing transformations.
The Operation enum represents the four basic arithmetic operations that
can be used to transform values during the routing process. Each operation
is designed to safely handle potential numerical errors using checked operations.
§Variants
Add- Addition operation (+)Subtract- Subtraction operation (-)Multiply- Multiplication operation (*)Divide- Division operation (/)
§Examples
use bothan_lib::registry::source::Operation;
use rust_decimal::Decimal;
// Create a multiplication operation
let operation = Operation::Multiply;
// Apply the operation to two values
let a = Decimal::new(10, 0); // 10.0
let b = Decimal::new(15, 0); // 15.0
let result = operation.execute(a, b).unwrap();
assert_eq!(result, Decimal::new(150, 0)); // 150.0Variants§
Add
Addition operation (+)
Subtract
Subtraction operation (-)
Multiply
Multiplication operation (*)
Divide
Division operation (/)
Implementations§
Source§impl Operation
impl Operation
Sourcepub fn execute<T>(&self, a: T, b: T) -> Option<T>
pub fn execute<T>(&self, a: T, b: T) -> Option<T>
Executes the arithmetic operation on two values.
This method applies the operation represented by the enum variant to the provided operands. It uses checked operations to prevent numerical errors such as overflow or division by zero.
§Examples
use bothan_lib::registry::source::Operation;
let add_op = Operation::Add;
assert_eq!(add_op.execute(5, 3), Some(8));
let div_op = Operation::Divide;
assert_eq!(div_op.execute(10, 2), Some(5));
assert_eq!(div_op.execute(10, 0), None); // Division by zero returns NoneTrait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for Operation
impl<'__de, __Context> BorrowDecode<'__de, __Context> for Operation
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Attempt to decode this type with the given BorrowDecode.
Source§impl<'de> Deserialize<'de> for Operation
impl<'de> Deserialize<'de> for Operation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Operation
Auto Trait Implementations§
impl Freeze for Operation
impl RefUnwindSafe for Operation
impl Send for Operation
impl Sync for Operation
impl Unpin for Operation
impl UnwindSafe for Operation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request