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

Commit 496efa5

Browse files
committed
Remove subclass::Boxed wrapper type
This is redundant with the GBoxed derive macro.
1 parent 818121b commit 496efa5

File tree

1 file changed

+1
-72
lines changed

1 file changed

+1
-72
lines changed

glib/src/subclass/boxed.rs

+1-72
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//! Module for registering boxed types for Rust types.
44
55
use crate::translate::*;
6-
use crate::value::*;
7-
use std::ops;
86

97
/// Trait for defining boxed types.
108
///
@@ -66,71 +64,12 @@ pub fn register_boxed_type<T: BoxedType>() -> crate::Type {
6664
}
6765
}
6866

69-
/// Wrapper struct for storing any `BoxedType` in `glib::Value`.
70-
///
71-
/// Instead of this the [`GBoxed!`] derive macro can be used to
72-
/// directly implement the relevant traits on the type itself.
73-
///
74-
/// [`GBoxed!`]: ../../derive.GBoxed.html
75-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
76-
pub struct Boxed<T: BoxedType>(pub T);
77-
78-
impl<T: BoxedType> ops::Deref for Boxed<T> {
79-
type Target = T;
80-
81-
fn deref(&self) -> &T {
82-
&self.0
83-
}
84-
}
85-
86-
impl<T: BoxedType> ops::DerefMut for Boxed<T> {
87-
fn deref_mut(&mut self) -> &mut T {
88-
&mut self.0
89-
}
90-
}
91-
92-
impl<T: BoxedType> crate::StaticType for Boxed<T> {
93-
fn static_type() -> crate::Type {
94-
T::get_type()
95-
}
96-
}
97-
98-
impl<T: BoxedType> SetValue for Boxed<T> {
99-
unsafe fn set_value(value: &mut Value, this: &Self) {
100-
let ptr: *mut Boxed<T> = Box::into_raw(Box::new(this.clone()));
101-
gobject_ffi::g_value_take_boxed(value.to_glib_none_mut().0, ptr as *mut _);
102-
}
103-
}
104-
105-
impl<T: BoxedType> SetValueOptional for Boxed<T> {
106-
unsafe fn set_value_optional(value: &mut Value, this: Option<&Self>) {
107-
let this = this.expect("None not allowed");
108-
let ptr: *mut Boxed<T> = Box::into_raw(Box::new(this.clone()));
109-
gobject_ffi::g_value_take_boxed(value.to_glib_none_mut().0, ptr as *mut _);
110-
}
111-
}
112-
113-
impl<'a, T: BoxedType> FromValueOptional<'a> for &'a Boxed<T> {
114-
unsafe fn from_value_optional(value: &'a Value) -> Option<Self> {
115-
let ptr = gobject_ffi::g_value_get_boxed(value.to_glib_none().0);
116-
assert!(!ptr.is_null());
117-
Some(&*(ptr as *mut Boxed<T>))
118-
}
119-
}
120-
121-
impl<'a, T: BoxedType> FromValue<'a> for &'a Boxed<T> {
122-
unsafe fn from_value(value: &'a Value) -> Self {
123-
let ptr = gobject_ffi::g_value_get_boxed(value.to_glib_none().0);
124-
assert!(!ptr.is_null());
125-
&*(ptr as *mut Boxed<T>)
126-
}
127-
}
128-
12967
#[cfg(test)]
13068
mod test {
13169
use super::*;
13270
// GBoxed macro assumes 'glib' is in scope
13371
use crate as glib;
72+
use crate::value::ToValue;
13473

13574
#[derive(Clone, Debug, PartialEq, Eq, glib::GBoxed)]
13675
#[gboxed(type_name = "MyBoxed")]
@@ -141,16 +80,6 @@ mod test {
14180
assert_ne!(crate::Type::Invalid, MyBoxed::get_type());
14281
}
14382

144-
#[test]
145-
fn test_value_boxed() {
146-
assert_ne!(crate::Type::Invalid, MyBoxed::get_type());
147-
148-
let b = Boxed(MyBoxed(String::from("abc")));
149-
let v = b.to_value();
150-
let b2 = v.get_some::<&Boxed<MyBoxed>>().unwrap();
151-
assert_eq!(&b, b2);
152-
}
153-
15483
#[test]
15584
fn test_value() {
15685
assert_ne!(crate::Type::Invalid, MyBoxed::get_type());

0 commit comments

Comments
 (0)