gst/format: introduce Constructor traits
- Oct 18, 2022
-
-
François Laignel authored
This commit makes the formatted values' main constructors `const`, so that they can be used in constant definitions. `from_usize` constructors can't be made const because `try_into` can't be used in `const` functions as of rustc 1.64.0. Same for `Percent::from_ratio`: floating point arithmetic is not allowed.
-
François Laignel authored
Introduce a set of Constructor traits which are implemented on integer of float depending on the formatted values. This traits allows building formatted values using expressions such as: ```rust let buffer_nb = 20.buffers(); let size = 42.k_bytes(); let duration = 15.minutes() + 30.seconds(); let quantity = 42.default_format(); let progress = 20.percent(); let progress = 0.2.percent_ratio(); ```
-