Skip to main content

select

Function select 

Source
pub fn select<T>(condition: bool, true_val: T, false_val: T) -> T
Expand description

Selects one of two values based on a condition.

This is a convenience function for conditional value selection, similar to the ternary operator in other languages.

§Type Parameters

  • T - The type of values to select from.

§Arguments

  • condition - If true, returns true_val; otherwise returns false_val.
  • true_val - The value to return if condition is true.
  • false_val - The value to return if condition is false.

§Returns

true_val if condition is true, otherwise false_val.

§Example

use matrix_gui::prelude::*;

let value = matrix_utils::select(true, 10, 20); // Returns 10
let value2 = matrix_utils::select(false, 10, 20); // Returns 20