Skip to content
Snippets Groups Projects

gst/format: introduce Constructor traits

Merged François Laignel requested to merge fengalin/gstreamer-rs:format-constructor-traits into main
  1. Oct 18, 2022
    • François Laignel's avatar
      gst/format: make `from_u64` constructors `const` · 49faa03c
      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.
      49faa03c
    • François Laignel's avatar
      gst/format: introduce Constructor traits · 384783b2
      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();
      ```
      384783b2
Loading