forked from mirrors/gstreamer-rs
gstreamer: format: Implement some more conversion traits
Specifically, `From<$formatted_type> for $inner` and `TryFrom<$formatted_type> for usize` for some types. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/492 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1329>
This commit is contained in:
parent
414019af21
commit
4d19d7b0b6
3 changed files with 38 additions and 0 deletions
|
@ -74,6 +74,14 @@ impl TryFromGlib<i64> for Other {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Other> for usize {
|
||||
type Error = std::num::TryFromIntError;
|
||||
|
||||
fn try_from(value: Other) -> Result<Self, Self::Error> {
|
||||
value.0.try_into()
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME `functions in traits cannot be const` (rustc 1.64.0)
|
||||
// rustdoc-stripper-ignore-next
|
||||
/// `Other` formatted value constructor trait.
|
||||
|
|
|
@ -281,6 +281,12 @@ macro_rules! impl_common_ops_for_newtype_uint(
|
|||
}
|
||||
}
|
||||
|
||||
impl From<$typ> for $inner {
|
||||
fn from(v: $typ) -> $inner {
|
||||
v.0
|
||||
}
|
||||
}
|
||||
|
||||
impl_trait_op_same!($typ, Add, add, AddAssign, add_assign);
|
||||
impl_trait_op_same!($typ, Sub, sub, SubAssign, sub_assign);
|
||||
impl std::ops::Div for $typ {
|
||||
|
|
|
@ -67,6 +67,14 @@ impl_format_value_traits!(Buffers, Buffers, Buffers, u64);
|
|||
option_glib_newtype_from_to!(Buffers, Buffers::OFFSET_NONE);
|
||||
glib_newtype_display!(Buffers, DisplayableOptionBuffers, Format::Buffers);
|
||||
|
||||
impl TryFrom<Buffers> for usize {
|
||||
type Error = std::num::TryFromIntError;
|
||||
|
||||
fn try_from(value: Buffers) -> Result<Self, Self::Error> {
|
||||
value.0.try_into()
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME `functions in traits cannot be const` (rustc 1.64.0)
|
||||
// rustdoc-stripper-ignore-next
|
||||
/// `Buffers` formatted value constructor trait.
|
||||
|
@ -143,6 +151,14 @@ impl_format_value_traits!(Bytes, Bytes, Bytes, u64);
|
|||
option_glib_newtype_from_to!(Bytes, u64::MAX);
|
||||
glib_newtype_display!(Bytes, DisplayableOptionBytes, Format::Bytes);
|
||||
|
||||
impl TryFrom<Bytes> for usize {
|
||||
type Error = std::num::TryFromIntError;
|
||||
|
||||
fn try_from(value: Bytes) -> Result<Self, Self::Error> {
|
||||
value.0.try_into()
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME `functions in traits cannot be const` (rustc 1.64.0)
|
||||
// rustdoc-stripper-ignore-next
|
||||
/// `Bytes` formatted value constructor trait.
|
||||
|
@ -240,6 +256,14 @@ impl_format_value_traits!(Default, Default, Default, u64);
|
|||
option_glib_newtype_from_to!(Default, u64::MAX);
|
||||
glib_newtype_display!(Default, DisplayableOptionDefault, Format::Default);
|
||||
|
||||
impl TryFrom<Default> for usize {
|
||||
type Error = std::num::TryFromIntError;
|
||||
|
||||
fn try_from(value: Default) -> Result<Self, Self::Error> {
|
||||
value.0.try_into()
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME `functions in traits cannot be const` (rustc 1.64.0)
|
||||
// rustdoc-stripper-ignore-next
|
||||
/// `Default` formatted value constructor trait.
|
||||
|
|
Loading…
Reference in a new issue