pub struct ClampedQuantity<T>where
T: IsQuantityFunction,{ /* private fields */ }Expand description
A wrapper around a type implementing IsQuantityFunction trait object which
clamps the output of IsQuantityFunction::call using the provided upper and
lower limits.
If the serde feature is not activated, it implements IsQuantityFunction
in a generic manner and can therefore be used in a QuantityFunction. If
serde is activated, it is unfortately not possible to provide a generic
implementation due to the macro #[typetag::serde] not being able to deal with
generics. As a workaround, it is possible to provide a simple custom
implementation for each concrete type in your own crate:
#[cfg_attr(feature = "serde", typetag::serde)]
impl IsQuantityFunction for ClampedQuantity<YourTypeHere> {
fn call(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64> {
return self.call_clamped(conditions);
}
}This approach is used for all the implementors of IsQuantityFunction provided
with this crate.
Implementations§
Source§impl<T> ClampedQuantity<T>where
T: IsQuantityFunction,
impl<T> ClampedQuantity<T>where
T: IsQuantityFunction,
Sourcepub fn new(
upper_limit: f64,
lower_limit: f64,
function: T,
) -> Result<ClampedQuantity<T>, &'static str>
pub fn new( upper_limit: f64, lower_limit: f64, function: T, ) -> Result<ClampedQuantity<T>, &'static str>
Checks if upper_limit >= lower_limit and returns a new instance of
ClampedQuantity if true.
Sourcepub fn inner(&self) -> &T
pub fn inner(&self) -> &T
Returns the underlying IsQuantityFunction.
Sourcepub fn inner_dyn(&self) -> &(dyn IsQuantityFunction + 'static)
pub fn inner_dyn(&self) -> &(dyn IsQuantityFunction + 'static)
Returns the underlying IsQuantityFunction as a trait object.
Sourcepub fn upper_limit(&self) -> f64
pub fn upper_limit(&self) -> f64
Returns the upper limit.
Sourcepub fn lower_limit(&self) -> f64
pub fn lower_limit(&self) -> f64
Returns the lower limit.
Sourcepub fn call_clamped(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64>
pub fn call_clamped(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64>
Clamps the output value of T::call using the provided upper and lower
limits. This function is mainly here to simplify custom IsQuantityFunction
implementations, see the ClampedQuantity docstring.
Trait Implementations§
Source§impl<T> Clone for ClampedQuantity<T>where
T: Clone + IsQuantityFunction,
impl<T> Clone for ClampedQuantity<T>where
T: Clone + IsQuantityFunction,
Source§fn clone(&self) -> ClampedQuantity<T>
fn clone(&self) -> ClampedQuantity<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'de, T> Deserialize<'de> for ClampedQuantity<T>where
T: IsQuantityFunction + Deserialize<'de>,
impl<'de, T> Deserialize<'de> for ClampedQuantity<T>where
T: IsQuantityFunction + Deserialize<'de>,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ClampedQuantity<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ClampedQuantity<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl IsQuantityFunction for ClampedQuantity<Exponential>
impl IsQuantityFunction for ClampedQuantity<Exponential>
Source§fn call(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64>
fn call(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64>
conditions. See the
IsQuantityFunction trait docstring for examples.Source§impl IsQuantityFunction for ClampedQuantity<FirstOrderTaylor>
impl IsQuantityFunction for ClampedQuantity<FirstOrderTaylor>
Source§fn call(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64>
fn call(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64>
conditions. See the
IsQuantityFunction trait docstring for examples.Source§impl IsQuantityFunction for ClampedQuantity<Linear>
impl IsQuantityFunction for ClampedQuantity<Linear>
Source§fn call(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64>
fn call(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64>
conditions. See the
IsQuantityFunction trait docstring for examples.Source§impl IsQuantityFunction for ClampedQuantity<Polynomial>
impl IsQuantityFunction for ClampedQuantity<Polynomial>
Source§fn call(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64>
fn call(&self, conditions: &[DynQuantity<f64>]) -> DynQuantity<f64>
conditions. See the
IsQuantityFunction trait docstring for examples.