Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
glib: Merge pull request #255 from sdroege/deref-mut-value
Browse files Browse the repository at this point in the history
Don't implement DerefMut on TypedValue
  • Loading branch information
GuillaumeGomez committed Nov 15, 2017
2 parents bbcb0ba + 2bb5d2d commit c9b0ccf
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/value.rs
Expand Up @@ -74,7 +74,7 @@ use std::borrow::Borrow;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::ops::{Deref, DerefMut};
use std::ops::Deref;
use std::ffi::CStr;
use std::ptr;
use libc::c_void;
Expand Down Expand Up @@ -185,7 +185,10 @@ impl fmt::Debug for Value {
unsafe {
let s: String = from_glib_full(
gobject_ffi::g_strdup_value_contents(self.to_glib_none().0));
write!(f, "Value({})", s)

f.debug_tuple("Value")
.field(&s)
.finish()
}
}
}
Expand Down Expand Up @@ -416,6 +419,8 @@ impl Drop for ValueArray {
/// accepted.
///
/// See the [module documentation](index.html) for more details.
#[derive(Clone)]
#[repr(C)]
pub struct TypedValue<T>(Value, PhantomData<*const T>);

impl<'a, T: FromValueOptional<'a> + SetValue> TypedValue<T> {
Expand All @@ -439,31 +444,27 @@ impl<'a, T: FromValueOptional<'a> + SetValue> TypedValue<T> {
///
/// This method is only available for types that support a `None` value.
pub fn set<U: ?Sized + SetValueOptional>(&mut self, value: Option<&U>) where T: Borrow<U> {
unsafe { SetValueOptional::set_value_optional(self, value) }
unsafe { SetValueOptional::set_value_optional(&mut self.0, value) }
}

/// Sets the value to `None`.
///
/// This method is only available for types that support a `None` value.
pub fn set_none(&mut self) where T: SetValueOptional {
unsafe { T::set_value_optional(self, None) }
unsafe { T::set_value_optional(&mut self.0, None) }
}

/// Sets the value.
pub fn set_some<U: ?Sized + SetValue>(&mut self, value: &U) where T: Borrow<U> {
unsafe { SetValue::set_value(self, value) }
}
}

impl<T> Clone for TypedValue<T> {
fn clone(&self) -> Self {
TypedValue(self.0.clone(), PhantomData)
unsafe { SetValue::set_value(&mut self.0, value) }
}
}

impl<T> fmt::Debug for TypedValue<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "TypedValue({:?})", self.0)
f.debug_tuple("TypedValue")
.field(&self.0)
.finish()
}
}

Expand All @@ -475,12 +476,6 @@ impl<T> Deref for TypedValue<T> {
}
}

impl<T> DerefMut for TypedValue<T> {
fn deref_mut(&mut self) -> &mut Value {
&mut self.0
}
}

impl<'a, T: FromValueOptional<'a> + SetValueOptional> From<Option<&'a T>> for TypedValue<T> {
fn from(value: Option<&'a T>) -> Self {
TypedValue(Value::from(value), PhantomData)
Expand Down

0 comments on commit c9b0ccf

Please sign in to comment.