From 2452f7f6a922f8fde4490d250eb195063e809067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 10 Aug 2017 01:13:28 +0300 Subject: [PATCH] Allow usage of Structures in GValues --- gstreamer/src/structure.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/gstreamer/src/structure.rs b/gstreamer/src/structure.rs index 83612c7a9..8c6f3b502 100644 --- a/gstreamer/src/structure.rs +++ b/gstreamer/src/structure.rs @@ -18,10 +18,12 @@ use std::marker::PhantomData; use Fraction; use glib; -use glib::translate::{from_glib, from_glib_full, FromGlibPtrFull, FromGlibPtrNone, Stash, - StashMut, ToGlib, ToGlibPtr, ToGlibPtrMut}; +use glib::translate::{from_glib, from_glib_full, from_glib_none, FromGlibPtrFull, FromGlibPtrNone, + GlibPtrDefault, Stash, StashMut, ToGlib, ToGlibPtr, ToGlibPtrMut}; use glib::value::{FromValueOptional, ToValue, Value}; use ffi; +use glib_ffi::gpointer; +use gobject_ffi; pub struct Structure(*mut StructureRef, PhantomData); @@ -225,6 +227,23 @@ impl FromGlibPtrFull<*mut ffi::GstStructure> for Structure { } } +impl<'a> glib::value::FromValueOptional<'a> for Structure { + unsafe fn from_value_optional(v: &'a glib::Value) -> Option { + let ptr = gobject_ffi::g_value_get_boxed(v.to_glib_none().0); + from_glib_none(ptr as *const ffi::GstStructure) + } +} + +impl glib::value::SetValue for Structure { + unsafe fn set_value(v: &mut glib::Value, s: &Self) { + gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, s.0 as gpointer); + } +} + +impl GlibPtrDefault for Structure { + type GlibType = *mut ffi::GstStructure; +} + #[repr(C)] pub struct StructureRef(ffi::GstStructure);