frequenz_microgrid_formula_engine/traits.rs
1// License: MIT
2// Copyright © 2024 Frequenz Energy-as-a-Service GmbH
3
4//! Traits used in the FormulaEngine.
5
6use std::ops::{Add, Div, Mul, Neg, Sub};
7
8/// Represents types that can be used in formula engines.
9pub trait NumberLike<T>:
10 Copy + Neg<Output = T> + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>
11{
12}
13
14/// Implement the NumberLike trait for all types that implement the required traits.
15impl<T, U> NumberLike<T> for U where
16 U: Copy
17 + Neg<Output = T>
18 + Add<Output = T>
19 + Sub<Output = T>
20 + Mul<Output = T>
21 + Div<Output = T>
22{
23}