{
"body": "Pass structs between Rust and C by defining a C-compatible struct with #[repr(C)] and exposing it via extern "C" functions.\n\nrust\nuse std::os::raw::c_int;\n\n#[repr(C)]\npub struct Point {\n x: c_int,\n y: c_int,\n}\n\n#[no_mangle]\npub extern \"C\" fn get_point() -> Point {\n Point { x: 10, y: 20 }\n}\n\n\nIn C, declare the same struct layout and call the function:\n\nc\n#include <stdio.h>\n\ntypedef struct {\n int x;\n int y;\n} Point;\n\nPoint get_point(void);\n\nint main() {\n Point p = get_point();\n printf(\"x=%d, y=%d\\n\", p.x, p.y);\n return 0;\n}\n",
"simple": "This lets Rust and C share data by agreeing on the exact layout of a group of values. You use it when you need to call existing C libraries from Rust or expose Rust logic to C programs. Think of it like two people agreeing on the order of items in a box so they can pass it back and forth without confusion.",
"summary": "Use #[repr(C)] structs and extern "C" functions to safely pass data between Rust and C."
}