Skip to content

Instantly share code, notes, and snippets.

@SiegeLord
Created April 13, 2014 17:57
Show Gist options
  • Select an option

  • Save SiegeLord/10594804 to your computer and use it in GitHub Desktop.

Select an option

Save SiegeLord/10594804 to your computer and use it in GitHub Desktop.
Connection
struct Connection
{
active: *mut bool,
payload: *mut c_void,
callback: fn(*mut c_void),
}
impl Connection
{
pub fn new(payload: *mut c_void, callback: fn(*mut c_void)) -> (Connection, Connection)
{
let active = unsafe
{
cast::transmute(~true)
};
(Connection{ active: active, payload: payload, callback: callback },
Connection{ active: active, payload: payload, callback: callback })
}
}
impl Drop for Connection
{
fn drop(&mut self)
{
if unsafe{ *self.active }
{
unsafe
{
*self.active = false;
}
(self.callback)(self.payload);
}
else
{
let _active: ~bool = unsafe { cast::transmute(self.active) };
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment