@@ -5,6 +5,10 @@ fn higher_level_types() {
5
5
#[ derive( Debug , glib:: ValueDelegate ) ]
6
6
pub struct MyVec ( Vec < String > ) ;
7
7
8
+ #[ derive( Debug , glib:: ValueDelegate ) ]
9
+ #[ value_delegate( nullable) ]
10
+ pub struct MyString ( Box < str > ) ;
11
+
8
12
#[ derive( Debug , glib:: ValueDelegate ) ]
9
13
#[ value_delegate( from = Option <String >) ]
10
14
struct MyVecManualFrom ( Vec < String > ) ;
@@ -23,7 +27,6 @@ fn higher_level_types() {
23
27
let vec = vec ! [ "foo" . to_string( ) , "bar" . to_string( ) ] ;
24
28
let vec_value = vec. to_value ( ) ;
25
29
let my_vec_value = MyVec ( vec. clone ( ) ) . to_value ( ) ;
26
-
27
30
assert_eq ! ( MyVec :: static_type( ) , Vec :: <String >:: static_type( ) ) ;
28
31
assert_eq ! (
29
32
vec_value. get:: <Vec <String >>( ) . unwrap( ) ,
@@ -38,10 +41,88 @@ fn higher_level_types() {
38
41
unsafe { MyVec :: from_value( & my_vec_value) . 0 }
39
42
) ;
40
43
44
+ let string = "foo" . to_string ( ) ;
45
+ let string_value = string. to_value ( ) ;
46
+ let my_string_value = MyString ( string. into ( ) ) . to_value ( ) ;
47
+ assert_eq ! ( MyString :: static_type( ) , Box :: <str >:: static_type( ) ) ;
48
+ assert_eq ! (
49
+ string_value. get:: <Box <str >>( ) . unwrap( ) ,
50
+ my_string_value. get:: <Box <str >>( ) . unwrap( ) ,
51
+ ) ;
52
+ assert_eq ! ( string_value. value_type( ) , my_string_value. value_type( ) ) ;
53
+ assert_eq ! ( unsafe { Box :: <str >:: from_value( & string_value) } , unsafe {
54
+ MyString :: from_value( & string_value) . 0
55
+ } ) ;
56
+ assert_eq ! (
57
+ unsafe { Box :: <str >:: from_value( & my_string_value) } ,
58
+ unsafe { MyString :: from_value( & my_string_value) . 0 }
59
+ ) ;
60
+
61
+ let string_some = Some ( "foo" . to_string ( ) ) ;
62
+ let string_some_value = string_some. to_value ( ) ;
63
+ let string_none_value = None :: < String > . to_value ( ) ;
64
+ let my_string_some_value = MyString ( string_some. unwrap ( ) . into ( ) ) . to_value ( ) ;
65
+ let my_string_none_value = None :: < MyString > . to_value ( ) ;
66
+ assert_eq ! (
67
+ Option :: <MyString >:: static_type( ) ,
68
+ Option :: <Box <str >>:: static_type( )
69
+ ) ;
70
+ assert_eq ! (
71
+ string_some_value
72
+ . get:: <Option <Box <str >>>( )
73
+ . unwrap( )
74
+ . unwrap( ) ,
75
+ my_string_some_value
76
+ . get:: <Option <Box <str >>>( )
77
+ . unwrap( )
78
+ . unwrap( ) ,
79
+ ) ;
80
+ assert_eq ! (
81
+ string_none_value
82
+ . get:: <Option <Box <str >>>( )
83
+ . unwrap( )
84
+ . is_none( ) ,
85
+ my_string_none_value
86
+ . get:: <Option <Box <str >>>( )
87
+ . unwrap( )
88
+ . is_none( ) ,
89
+ ) ;
90
+ assert_eq ! (
91
+ string_some_value. value_type( ) ,
92
+ my_string_some_value. value_type( )
93
+ ) ;
94
+ assert_eq ! (
95
+ string_none_value. value_type( ) ,
96
+ my_string_none_value. value_type( )
97
+ ) ;
98
+ assert_eq ! (
99
+ unsafe { Option :: <Box <str >>:: from_value( & string_some_value) . unwrap( ) } ,
100
+ unsafe {
101
+ Option :: <MyString >:: from_value( & string_some_value)
102
+ . unwrap( )
103
+ . 0
104
+ }
105
+ ) ;
106
+ assert_eq ! (
107
+ unsafe { Option :: <Box <str >>:: from_value( & string_none_value) . is_none( ) } ,
108
+ unsafe { Option :: <MyString >:: from_value( & string_none_value) . is_none( ) }
109
+ ) ;
110
+ assert_eq ! (
111
+ unsafe { Option :: <Box <str >>:: from_value( & my_string_some_value) . unwrap( ) } ,
112
+ unsafe {
113
+ Option :: <MyString >:: from_value( & my_string_some_value)
114
+ . unwrap( )
115
+ . 0
116
+ }
117
+ ) ;
118
+ assert_eq ! (
119
+ unsafe { Option :: <Box <str >>:: from_value( & my_string_none_value) . is_none( ) } ,
120
+ unsafe { Option :: <MyString >:: from_value( & my_string_none_value) . is_none( ) }
121
+ ) ;
122
+
41
123
let opt = Some ( "foo" . to_string ( ) ) ;
42
124
let opt_value = opt. to_value ( ) ;
43
125
let my_vec_manual_from_value = MyVecManualFrom :: from ( opt) . to_value ( ) ;
44
-
45
126
assert_eq ! (
46
127
MyVecManualFrom :: static_type( ) ,
47
128
Option :: <String >:: static_type( )
0 commit comments