The C side

Our C program is c_src/main.c. We need a few system headers before we can define the embed_quantiles interface:

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

The only slightly unusual one is time.h. We pull that in because we're going to be pushing random floats into the CKMS structure. Not cryptographically secure randomness, mind. Here's the C view of the Rust API we just created:

struct ckms;

struct ckms* alloc_ckms(double error);
void free_ckms(struct ckms* ckms);
void ckms_insert(struct ckms* ckms, float value);
int8_t query(struct ckms* ckms, double q, float* quant);

Notice the CKMS struct . That's the opaque struct. C is now aware there is a structure but it doesn't know how big it is. That's ...

Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.