convert_all_floats

Macro convert_all_floats 

Source
macro_rules! convert_all_floats {
    ($( $item:expr ),* $(,)?) => { ... };
}
Expand description

A convenience macro that uses the convert_all macro with the convert_float_conversion_error function for error handling.

Each item provided is attempted to be converted into a floating point number. If any of the conversions fail, it short-circuits and returns the error. This macro must be used in the context of a function that returns a Result because it uses the ? operator. It is primarily useful for defining function like the one shown in the example below that are generic in some parameter that can implements TryFrom.

ยงExample

use subtr_actor::*;

pub fn some_constant_function<F: TryFrom<f32>>(
    rigid_body: &boxcars::RigidBody,
) -> SubtrActorResult<[F; 3]> {
    convert_all_floats!(42.0, 0.0, 1.234)
}