Skip to main content

IfThenElse

Trait IfThenElse 

Source
pub trait IfThenElse<T> {
    // Required method
    fn if_then_else<U, V>(self, a: U, b: V) -> T
       where T: From<U> + From<V>;
}
Expand description

A trait to produce an if-then-else expression.

§Examples

use dypdl::prelude::*;

let mut model = Model::default();
let variable = model.add_integer_variable("variable", 1).unwrap();
let state = model.target.clone();
let mut function_cache = StateFunctionCache::new(&model.state_functions);

let condition = Condition::comparison_i(ComparisonOperator::Ge, variable, 1);
let expression: IntegerExpression = condition.if_then_else(variable, 0);
assert_eq!(
    expression.eval(
        &state, &mut function_cache, &model.state_functions, &model.table_registry,
    ),
    1,
);

let condition = Condition::comparison_i(ComparisonOperator::Gt, variable, 1);
let expression: IntegerExpression = condition.if_then_else(variable, IntegerExpression::from(0));
assert_eq!(
    expression.eval(
        &state, &mut function_cache, &model.state_functions, &model.table_registry,
    ),
    0,
);

Required Methods§

Source

fn if_then_else<U, V>(self, a: U, b: V) -> T
where T: From<U> + From<V>,

Returns an if-then-else expression, which returns a if this condition holds and b otherwise.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§