Calling slightly complex C APIs from rust


This is the stuff that is declared in the header file

struct mosquitto_message{
	int mid;
	char *topic;
	void *payload;
	int payloadlen;
	int qos;
	bool retain;

struct mosquitto;

struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *obj);
int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int qos);
void mosquitto_message_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *));

The C code which is calling the above APIs

struct client_info {
    struct mosquitto *m;
    pid_t pid;
    uint32_t tick_ct;

void *udata = (void *)info;
struct mosquitto *m = mosquitto_new(buf, true, udata);
int res = mosquitto_publish(m, NULL, tock_pid,  payloadlen, payload, 0, false);

static void on_message(struct mosquitto *m, void *udata, const struct mosquitto_message *msg) {

mosquitto_message_callback_set(m, on_message);

What is the best possible way to call these C APIs in my rust code. The examples in book are not of much help as they are too simple. Please help with some sample code.