Commit graph

14 commits

Author SHA1 Message Date
Sebastian Dröge f24b38470b Fix various new clippy warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1203>
2023-01-25 10:18:33 +02:00
Sebastian Dröge f235dc987d Inline various trivial functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1177>
2023-01-11 11:33:54 +02:00
François Laignel 49faa03c98 gst/format: make from_u64 constructors const
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.
2022-10-18 11:24:57 +02:00
François Laignel 384783b242 gst/format: introduce Constructor traits
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();
```
2022-10-18 11:24:08 +02:00
François Laignel dcf6d16496 gst/format: new panicking constructors and some Percent fixes
Previous proposition for constructing specific formatted values was
to use an operation such as `42 * Default::ONE` which, in retrospect,
doesn't seem idiomatic.

This commit adds `from_u64` and `from_usize` constructors for most
formatted values. Having `from_usize` is convenient when dealing with
quantities related to containers indices or length.

This also fixes the `Percent` from float constructors from which was
derived the `ONE` constant as well as previous display implementation.

Also removed the `pub` specifier for `Undefined` inner value. It wasn't
removed in a previous commit as `Undefined` can use the full range of
the inner type. But now, it seems preferable not to expose the inner
value for proper encapsulation and so as to reduce the differences with
other formatted values (kind of least astonishment principle).
2022-10-11 13:25:53 +02:00
François Laignel 08551bb1bc format/specific: don't expose inner as pub
... users would be able to bypass the range checks and build a
defined Rust value which would be interpreted as `None` in C code.

Added format module examples for formatted values constructions.
2022-10-10 19:23:35 +02:00
François Laignel f6336b1be3 gst/format: fix Percent Display impl
- The `GST_FORMAT_PERCENT_SCALE` was not used to compute the value
  to display.
- Added `Display` examples in the format module documentation.
- Simplified `glib_newtype_display` macro.
2022-10-10 18:44:59 +02:00
François Laignel 8e2c621a9f gst/lib: cleanup format re-exports 2022-10-10 15:10:10 +02:00
François Laignel 274a5bd020 gst/format: implement GenericSignedFormattedValue
The `Signed` version for `GenericFormattedValue` was implemented as
`Signed<GenericFormattedValue>`, which failed to represent properly
the `None` variants when applicable and could represent inconsistent
`Signed` variant combined with `GenericFormattedValue` formats which
are internaly represented as signed integers.
2022-10-09 20:00:40 +02:00
François Laignel 04b6710f84 format/Other: use u64 internally instead of i64 2022-10-09 20:00:38 +02:00
François Laignel 8a7813d04c gst: move format_serde.rs under format module 2022-10-09 18:53:57 +02:00
François Laignel bff1354b74 gst/format: module doc 2022-10-01 13:16:06 +02:00
François Laignel eb4d997f0a gst/format: shuffle types and traits 2022-10-01 00:49:42 +02:00
François Laignel 79377337a4 gst/format: move related modules under a directory 2022-10-01 00:49:39 +02:00
Renamed from gstreamer/src/format.rs (Browse further)