diff --git a/src/value.rs b/src/value.rs index 38be978a..b41dc8b8 100644 --- a/src/value.rs +++ b/src/value.rs @@ -362,12 +362,12 @@ pub trait ToValue { fn to_value_type(&self) -> Type; } -impl<'a, T: ?Sized + SetValueOptional> ToValue for Option<&'a T> { +impl ToValue for Option { fn to_value(&self) -> Value { unsafe { let mut ret = Value::uninitialized(); gobject_ffi::g_value_init(ret.to_glib_none_mut().0, T::static_type().to_glib()); - T::set_value_optional(&mut ret, self.clone()); + T::set_value_optional(&mut ret, self.as_ref()); ret } } @@ -448,15 +448,15 @@ impl SetValueOptional for str { } } -impl<'a> SetValue for &'a str { +impl<'a, T: ?Sized + SetValue> SetValue for &'a T { unsafe fn set_value(value: &mut Value, this: &Self) { - gobject_ffi::g_value_take_string(value.to_glib_none_mut().0, this.to_glib_full()) + SetValue::set_value(value, *this) } } -impl<'a> SetValueOptional for &'a str { +impl<'a, T: ?Sized + SetValueOptional> SetValueOptional for &'a T { unsafe fn set_value_optional(value: &mut Value, this: Option<&Self>) { - gobject_ffi::g_value_take_string(value.to_glib_none_mut().0, this.to_glib_full()) + SetValueOptional::set_value_optional(value, this.map(|v| *v)) } } @@ -491,12 +491,6 @@ impl> SetValueOptional for T { } } -impl<'a, T: IsA> SetValue for &'a T { - unsafe fn set_value(value: &mut Value, this: &Self) { - gobject_ffi::g_value_set_object(value.to_glib_none_mut().0, this.to_glib_none().0) - } -} - impl FromValueOptional for bool { unsafe fn from_value_optional(value: &Value) -> Option { Some(from_glib(gobject_ffi::g_value_get_boolean(value.to_glib_none().0)))