gstreamer-rs/gstreamer/src/static_caps.rs

157 lines
4.2 KiB
Rust
Raw Normal View History

2020-12-15 10:53:31 +00:00
// Take a look at the license at the top of the repository in the LICENSE file.
use std::{fmt, marker::PhantomData, ptr};
use glib::{prelude::*, translate::*};
use crate::Caps;
2018-04-01 08:29:15 +00:00
#[doc(alias = "GstStaticCaps")]
#[derive(Clone, Copy)]
pub struct StaticCaps(ptr::NonNull<ffi::GstStaticCaps>);
impl StaticCaps {
#[doc(alias = "gst_static_caps_get")]
#[inline]
pub fn get(&self) -> Caps {
unsafe { from_glib_full(ffi::gst_static_caps_get(self.0.as_ptr())) }
}
}
unsafe impl Send for StaticCaps {}
unsafe impl Sync for StaticCaps {}
impl fmt::Debug for StaticCaps {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("StaticCaps")
.field("str", &unsafe {
glib::GStr::from_ptr(self.0.as_ref().string)
})
.finish()
}
}
impl StaticType for StaticCaps {
#[inline]
fn static_type() -> glib::types::Type {
unsafe { glib::translate::from_glib(ffi::gst_static_caps_get_type()) }
}
}
2021-04-20 07:19:02 +00:00
impl glib::value::ValueType for StaticCaps {
type Type = Self;
}
unsafe impl glib::translate::TransparentPtrType for StaticCaps {}
#[doc(hidden)]
2021-04-20 07:19:02 +00:00
unsafe impl<'a> glib::value::FromValue<'a> for StaticCaps {
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
#[inline]
2021-04-20 07:19:02 +00:00
unsafe fn from_value(value: &'a glib::Value) -> Self {
skip_assert_initialized!();
from_glib_none(
glib::gobject_ffi::g_value_get_boxed(value.to_glib_none().0) as *mut ffi::GstStaticCaps
)
}
}
#[doc(hidden)]
2021-04-20 07:19:02 +00:00
impl glib::value::ToValue for StaticCaps {
#[inline]
2021-04-20 07:19:02 +00:00
fn to_value(&self) -> glib::Value {
let mut value = glib::Value::for_value_type::<Self>();
2021-04-20 07:19:02 +00:00
unsafe {
glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0,
self.to_glib_none().0 as *mut _,
)
}
value
}
#[inline]
2021-04-20 07:19:02 +00:00
fn value_type(&self) -> glib::Type {
Self::static_type()
}
}
impl From<StaticCaps> for glib::Value {
#[inline]
fn from(v: StaticCaps) -> glib::Value {
skip_assert_initialized!();
glib::value::ToValue::to_value(&v)
}
}
#[doc(hidden)]
2021-04-20 07:19:02 +00:00
impl glib::value::ToValueOptional for StaticCaps {
#[inline]
2021-04-20 07:19:02 +00:00
fn to_value_optional(s: Option<&Self>) -> glib::Value {
skip_assert_initialized!();
let mut value = glib::Value::for_value_type::<Self>();
2021-04-20 07:19:02 +00:00
unsafe {
glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0,
s.to_glib_none().0 as *mut _,
)
}
value
}
}
#[doc(hidden)]
impl glib::translate::GlibPtrDefault for StaticCaps {
type GlibType = *mut ffi::GstStaticCaps;
}
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticCaps> for StaticCaps {
type Storage = PhantomData<&'a StaticCaps>;
#[inline]
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstStaticCaps, Self> {
glib::translate::Stash(self.0.as_ptr(), PhantomData)
}
fn to_glib_full(&self) -> *const ffi::GstStaticCaps {
unimplemented!()
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticCaps> for StaticCaps {
#[inline]
unsafe fn from_glib_none(ptr: *const ffi::GstStaticCaps) -> Self {
debug_assert!(!ptr.is_null());
2018-04-01 08:29:15 +00:00
StaticCaps(ptr::NonNull::new_unchecked(ptr as *mut _))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticCaps> for StaticCaps {
#[inline]
unsafe fn from_glib_none(ptr: *mut ffi::GstStaticCaps) -> Self {
debug_assert!(!ptr.is_null());
2018-04-01 08:29:15 +00:00
StaticCaps(ptr::NonNull::new_unchecked(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticCaps> for StaticCaps {
#[inline]
unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticCaps) -> Borrowed<Self> {
debug_assert!(!ptr.is_null());
Borrowed::new(StaticCaps(ptr::NonNull::new_unchecked(ptr)))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticCaps> for StaticCaps {
#[inline]
unsafe fn from_glib_full(_ptr: *mut ffi::GstStaticCaps) -> Self {
unimplemented!();
}
}