Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Adjust ToValue implementation to support both Option<T> and Option<&T> #114

Merged
merged 1 commit into from
Mar 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,12 @@ pub trait ToValue {
fn to_value_type(&self) -> Type;
}

impl<'a, T: ?Sized + SetValueOptional> ToValue for Option<&'a T> {
impl<T: SetValueOptional> ToValue for Option<T> {
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
}
}
Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -491,12 +491,6 @@ impl<T: IsA<Object>> SetValueOptional for T {
}
}

impl<'a, T: IsA<Object>> 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<Self> {
Some(from_glib(gobject_ffi::g_value_get_boolean(value.to_glib_none().0)))
Expand Down