Skip to content

Instantly share code, notes, and snippets.

@rrichardson
Created February 2, 2015 20:29
Show Gist options
  • Save rrichardson/66add0d754707d71de3d to your computer and use it in GitHub Desktop.
Save rrichardson/66add0d754707d71de3d to your computer and use it in GitHub Desktop.
pub struct DropCopyProto;
impl Protocol for DropCopyProto {
type Output = DropCopy;
fn new() -> DropCopyProto {
DropCopyProto
}
fn append(&mut self, buf: &AROIobuf) -> Option<(<Self as Protocol>::Output, AROIobuf, u32)> {
let size = mem::size_of::<DropCopy>() as u32;
if buf.len() >= size {
let (a, b) = buf.split_at(size).unwrap();
let val = unsafe { *(mem::transmute::<*mut u8, *const DropCopy>(a.ptr())) };
Some((val, b, size))
} else {
None
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment