Files
medicallib_rust/ffi/medicallib.h
T
zack3d b5b6619118 refactor(ffi): generate header via cbindgen
Adopt cbindgen in the build script to keep the C header aligned with the
Rust FFI definitions. Store the patient handle as a void pointer to avoid
layout mismatches and refresh the generated header and repository
guidelines.
2025-09-23 23:16:53 -07:00

147 lines
2.6 KiB
C

#ifndef MEDICALLIB_RUST_MEDICALLIB_H
#define MEDICALLIB_RUST_MEDICALLIB_H
#pragma once
/* This file is generated by cbindgen. Do not edit manually. */
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
/**
* Successful return code.
*/
#define ML_OK 0
/**
* Generic error.
*/
#define ML_ERR 1
/**
* Invalid argument.
*/
#define ML_EINVAL 2
/**
* Organ code for `OrganType::Heart`.
*/
#define ML_ORGAN_HEART 0
/**
* Organ code for `OrganType::Lungs`.
*/
#define ML_ORGAN_LUNGS 1
/**
* Organ code for `OrganType::Brain`.
*/
#define ML_ORGAN_BRAIN 2
/**
* Organ code for `OrganType::SpinalCord`.
*/
#define ML_ORGAN_SPINAL_CORD 3
/**
* Organ code for `OrganType::Stomach`.
*/
#define ML_ORGAN_STOMACH 4
/**
* Organ code for `OrganType::Liver`.
*/
#define ML_ORGAN_LIVER 5
/**
* Organ code for `OrganType::Gallbladder`.
*/
#define ML_ORGAN_GALLBLADDER 6
/**
* Organ code for `OrganType::Pancreas`.
*/
#define ML_ORGAN_PANCREAS 7
/**
* Organ code for `OrganType::Intestines`.
*/
#define ML_ORGAN_INTESTINES 8
/**
* Organ code for `OrganType::Esophagus`.
*/
#define ML_ORGAN_ESOPHAGUS 9
/**
* Organ code for `OrganType::Kidneys`.
*/
#define ML_ORGAN_KIDNEYS 10
/**
* Organ code for `OrganType::Bladder`.
*/
#define ML_ORGAN_BLADDER 11
/**
* Organ code for `OrganType::Spleen`.
*/
#define ML_ORGAN_SPLEEN 12
/**
* Opaque patient handle type for C consumers. Wraps a heap-allocated `Patient`.
*/
typedef struct MLPatient {
void *inner;
} MLPatient;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**
* Compute BMI; returns 0 on success, non-zero on error.
* On success writes result to `out_bmi`.
*/
int32_t medicallib_bmi(float weight_kg, float height_m, float *out_bmi);
/**
* Create a new patient with id string. Returns null on error.
*/
struct MLPatient *ml_patient_new(const char *id);
/**
* Destroy a patient handle. Accepts null.
*/
void ml_patient_free(struct MLPatient *p);
/**
* Get a newly-allocated C string summary for the patient.
* Returns null on error. Free the returned string with `ml_string_free`.
*/
char *ml_patient_summary(const struct MLPatient *p);
/**
* Frees a C string previously returned by this library. Accepts null.
*/
void ml_string_free(char *s);
/**
* Advance patient simulation by dt seconds.
*/
int32_t ml_patient_update(struct MLPatient *p, float dt_seconds);
/**
* Return organ summary by type code. See header for codes. Caller frees string.
*/
char *ml_patient_organ_summary(const struct MLPatient *p, uint32_t organ_code);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif /* MEDICALLIB_RUST_MEDICALLIB_H */