API

1

Modules and Files: from .h/.c to mod

5 minute

C projects commonly split .h and .c files like this:

packet.h   -> public structs, functions, macros
packet.c   -> function implementations and private helpers
main.c     -> includes packet.h and calls public functions

For example:

/* packet.h */
int packet_parse(const uint8_t *data, size_t len, struct Packet *out);

/* packet.c */
static int parse_header(const uint8_t *data, size_t len);

int packet_parse(const uint8_t *data, size_t len, struct Packet *out)
{
    /* ... */
}

Rust also separates files, internal implementation, and public APIs, but the model is not #include. The first mapping is:

C .h/.c         -> Rust module + pub
C include       -> Rust use / module path
C static helper -> Rust private function by default
C public header -> Rust pub API

Cargo.toml describes the package

C projects usually rely on Makefiles, CMake, or another build system to describe source files, include paths, and library outputs.

Read More