Skip to content

Instantly share code, notes, and snippets.

@JFreegman
Last active October 11, 2017 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JFreegman/c459ccbe66e2f9a06eda7bd3392841d2 to your computer and use it in GitHub Desktop.
Save JFreegman/c459ccbe66e2f9a06eda7bd3392841d2 to your computer and use it in GitHub Desktop.
/* Basic rust callback function */
pub fn func(data: &[u8], src_addr: &SocketAddr, obj: &Rc<RefCell<Any>>) {
let mut temp = obj.borrow_mut();
let mut dht = match temp.downcast_mut::<DHT>() {
Some(dht) => dht,
None => return,
};
...
}
/* Equivalent in C */
void func(const char *data, const IP_Port *src_addr, void *obj)
{
DHT *dht = obj;
if (!dht) {
return;
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment