@@ -19,6 +19,47 @@ pub fn baz_1(a: Ptr<i32>, b: Option<Ptr<i32>>) -> bool {
1919 _lhs == ( * b. borrow ( ) ) . clone ( )
2020 } ;
2121}
22+ #[ derive( ) ]
23+ pub struct Bar {
24+ pub v : Value < i32 > ,
25+ }
26+ impl Bar {
27+ pub fn Bar ( v : Option < i32 > ) -> Self {
28+ let v: Value < i32 > = Rc :: new ( RefCell :: new ( v. unwrap_or ( 1 ) ) ) ;
29+ let __this: Value < Bar > = Rc :: new ( RefCell :: new ( Self {
30+ v : Rc :: new ( RefCell :: new ( ( * v. borrow ( ) ) ) ) ,
31+ } ) ) ;
32+ let this: Ptr < Bar > = __this. as_pointer ( ) ;
33+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
34+ }
35+ }
36+ impl Clone for Bar {
37+ fn clone ( & self ) -> Self {
38+ let __this: Value < Bar > = Rc :: new ( RefCell :: new ( Self {
39+ v : Rc :: new ( RefCell :: new ( ( * self . v . borrow ( ) ) ) ) ,
40+ } ) ) ;
41+ let this: Ptr < Bar > = __this. as_pointer ( ) ;
42+ Rc :: try_unwrap ( __this) . ok ( ) . unwrap ( ) . into_inner ( )
43+ }
44+ }
45+ impl Default for Bar {
46+ fn default ( ) -> Self {
47+ { Bar :: Bar ( None ) }
48+ }
49+ }
50+ impl ByteRepr for Bar {
51+ fn byte_size ( ) -> usize {
52+ 4
53+ }
54+ fn to_bytes ( & self , buf : & mut [ u8 ] ) {
55+ ( * self . v . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..4 ] ) ;
56+ }
57+ fn from_bytes ( buf : & [ u8 ] ) -> Self {
58+ Self {
59+ v : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 0 ..4 ] ) ) ) ,
60+ }
61+ }
62+ }
2263pub fn main ( ) {
2364 std:: process:: exit ( main_0 ( ) ) ;
2465}
@@ -35,5 +76,15 @@ fn main_0() -> i32 {
3576 } ) as i32 )
3677 == ( true as i32 ) )
3778 ) ;
79+ let b: Value < Bar > = Rc :: new ( RefCell :: new ( Bar :: Bar ( { Some ( ) } ) ) ) ;
80+ assert ! ( ( ( * ( * b. borrow( ) ) . v. borrow( ) ) == 1 ) ) ;
81+ assert ! ( ( ( * Bar :: Bar ( { Some ( 2 ) } , ) . v. borrow( ) ) == 2 ) ) ;
82+ let arr: Value < Box < [ Bar ] > > = Rc :: new ( RefCell :: new ( Box :: new ( [
83+ Bar :: Bar ( { Some ( ) } ) ,
84+ Bar :: Bar ( { Some ( ) } ) ,
85+ Bar :: Bar ( { Some ( ) } ) ,
86+ ] ) ) ) ;
87+ assert ! ( ( ( * ( * arr. borrow( ) ) [ ( 0 ) as usize ] . v. borrow( ) ) == 1 ) ) ;
88+ assert ! ( ( ( * ( * arr. borrow( ) ) [ ( 2 ) as usize ] . v. borrow( ) ) == 1 ) ) ;
3889 return 0 ;
3990}
0 commit comments