3
3
//! Module for registering boxed types for Rust types.
4
4
5
5
use crate :: translate:: * ;
6
- use crate :: value:: * ;
7
- use std:: ops;
8
6
9
7
/// Trait for defining boxed types.
10
8
///
@@ -66,71 +64,12 @@ pub fn register_boxed_type<T: BoxedType>() -> crate::Type {
66
64
}
67
65
}
68
66
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
-
129
67
#[ cfg( test) ]
130
68
mod test {
131
69
use super :: * ;
132
70
// GBoxed macro assumes 'glib' is in scope
133
71
use crate as glib;
72
+ use crate :: value:: ToValue ;
134
73
135
74
#[ derive( Clone , Debug , PartialEq , Eq , glib:: GBoxed ) ]
136
75
#[ gboxed( type_name = "MyBoxed" ) ]
@@ -141,16 +80,6 @@ mod test {
141
80
assert_ne ! ( crate :: Type :: Invalid , MyBoxed :: get_type( ) ) ;
142
81
}
143
82
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
-
154
83
#[ test]
155
84
fn test_value ( ) {
156
85
assert_ne ! ( crate :: Type :: Invalid , MyBoxed :: get_type( ) ) ;
0 commit comments