|
| 1 | +extern crate libcc2rs; |
| 2 | +use libcc2rs::*; |
| 3 | +use std::cell::RefCell; |
| 4 | +use std::collections::BTreeMap; |
| 5 | +use std::io::prelude::*; |
| 6 | +use std::io::{Read, Seek, Write}; |
| 7 | +use std::os::fd::AsFd; |
| 8 | +use std::rc::{Rc, Weak}; |
| 9 | +#[derive()] |
| 10 | +pub struct pair { |
| 11 | + pub a: Value<Box<[i32]>>, |
| 12 | + pub b: Value<Box<[i32]>>, |
| 13 | +} |
| 14 | +impl Default for pair { |
| 15 | + fn default() -> Self { |
| 16 | + pair { |
| 17 | + a: Rc::new(RefCell::new( |
| 18 | + (0..4).map(|_| <i32>::default()).collect::<Box<[i32]>>(), |
| 19 | + )), |
| 20 | + b: Rc::new(RefCell::new( |
| 21 | + (0..4).map(|_| <i32>::default()).collect::<Box<[i32]>>(), |
| 22 | + )), |
| 23 | + } |
| 24 | + } |
| 25 | +} |
| 26 | +impl ByteRepr for pair { |
| 27 | + fn byte_size() -> usize { |
| 28 | + 32 |
| 29 | + } |
| 30 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 31 | + (*self.a.borrow()).to_bytes(&mut buf[0..16]); |
| 32 | + (*self.b.borrow()).to_bytes(&mut buf[16..32]); |
| 33 | + } |
| 34 | + fn from_bytes(buf: &[u8]) -> Self { |
| 35 | + Self { |
| 36 | + a: Rc::new(RefCell::new(<Box<[i32]>>::from_bytes(&buf[0..16]))), |
| 37 | + b: Rc::new(RefCell::new(<Box<[i32]>>::from_bytes(&buf[16..32]))), |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | +pub fn main() { |
| 42 | + std::process::exit(main_0()); |
| 43 | +} |
| 44 | +fn main_0() -> i32 { |
| 45 | + let s: Value<pair> = <Value<pair>>::default(); |
| 46 | + assert!( |
| 47 | + (((((*s.borrow()).a.as_pointer() as Ptr::<i32>).offset((4) as isize) |
| 48 | + == ((*s.borrow()).b.as_pointer() as Ptr::<i32>)) as i32) |
| 49 | + != 0) |
| 50 | + ); |
| 51 | + return 0; |
| 52 | +} |
0 commit comments