Last active
October 11, 2017 16:36
-
-
Save JFreegman/c459ccbe66e2f9a06eda7bd3392841d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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