compiles with custom bytes convertable arguments
This commit is contained in:
@@ -32,13 +32,23 @@ pub struct CustomData {
|
||||
|
||||
impl FromRawBytes for CustomData {
|
||||
fn from_bytes(bytes: &[u8]) -> Result<CustomData, FromBytesError> {
|
||||
Ok(CustomData { a: bytes[0] * 256 + bytes[1], b: bytes[2] * 256 + bytes[3]})
|
||||
Ok(CustomData {
|
||||
a: bytes[0] as usize * 256 + bytes[1] as usize,
|
||||
b: bytes[2] as usize * 256 + bytes[3] as usize
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl BytesConvertable for CustomData {
|
||||
fn bytes(&self) -> &[u8] {
|
||||
unsafe { &::std::mem::transmute::<[u8;8]>(self) }
|
||||
let ip: *const CustomData = self;
|
||||
let ptr: *const u8 = ip as *const _;
|
||||
unsafe {
|
||||
::std::slice::from_raw_parts(
|
||||
ptr,
|
||||
::std::mem::size_of::<i64>()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +66,8 @@ impl Service {
|
||||
(a_0 - b) as i32
|
||||
}
|
||||
pub fn push_custom(&self, data: CustomData) -> bool {
|
||||
let clock = self.commits.write().unwrap();
|
||||
let rlock = self.commits.write().unwrap();
|
||||
let mut clock = self.commits.write().unwrap();
|
||||
let mut rlock = self.commits.write().unwrap();
|
||||
|
||||
*clock = data.a;
|
||||
*rlock = data.b;
|
||||
|
||||
Reference in New Issue
Block a user