How do I declare a Numeric data type

In this code:

            ui.label("Some text");
                Slider::new(value, 0..=100)
                    .text("f64 demo slider"),

Under this code

Slider::new(value, 0..=100)

the value requires the data type Numeric.

How do I declare a variable with a Numeric data type?

For f32 data type I type let value = 10f32. But how would I do it for Numeric?

I am looking through this but can't seem to find a way to declare a Numeric data type.

Numeric is a trait, and trait is not type. trait is an abstract behavior/constraint across types. A variable can have only single type, though the type may be an enum or a trait object.

1 Like

From the docs, you might try converting value to Numeric with something like:

Slider::new(emath::Numeric::from_f64(value), 0..=100)

I have not used the crate before, tho.

1 Like

This cannot work (even if it was of any use here), since Numeric it not object-safe.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.