pub trait WeightElement:
Clone
+ Default
+ 'static {
type Sum: NumericSize;
const IS_UNIT: bool;
// Required methods
fn unit() -> Self;
fn validate_element(&self, context: &str) -> Result<(), ConstructionError>;
fn to_sum(&self) -> Self::Sum;
// Provided methods
fn checked_add_to_sum(
total: Self::Sum,
value: Self::Sum,
context: &str,
) -> Result<Self::Sum, EvaluationError> { ... }
fn checked_mul_sum(
left: Self::Sum,
right: Self::Sum,
context: &str,
) -> Result<Self::Sum, EvaluationError> { ... }
}Expand description
Maps a weight element to its sum/metric type.
This decouples the per-element weight type from the accumulation type.
Exact integer weights use a wider accumulation type: i64 and the unit
weight One both use i64. Approximate f64 weights continue to sum
into f64.
Required Associated Constants§
Required Associated Types§
Sourcetype Sum: NumericSize
type Sum: NumericSize
The numeric type used for sums and comparisons.
Required Methods§
Sourcefn validate_element(&self, context: &str) -> Result<(), ConstructionError>
fn validate_element(&self, context: &str) -> Result<(), ConstructionError>
Validate that an element belongs to the public weight domain.
Provided Methods§
Sourcefn checked_add_to_sum(
total: Self::Sum,
value: Self::Sum,
context: &str,
) -> Result<Self::Sum, EvaluationError>
fn checked_add_to_sum( total: Self::Sum, value: Self::Sum, context: &str, ) -> Result<Self::Sum, EvaluationError>
Add one element to an evaluated objective without overflowing or producing a non-finite value.
Sourcefn checked_mul_sum(
left: Self::Sum,
right: Self::Sum,
context: &str,
) -> Result<Self::Sum, EvaluationError>
fn checked_mul_sum( left: Self::Sum, right: Self::Sum, context: &str, ) -> Result<Self::Sum, EvaluationError>
Multiply evaluated quantities without overflowing or producing a non-finite value.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".