Interface to C API¶
When the user requires extra flexibility that MuJoCo-rs does not offer, direct FFI bindings to the C language structs and functions can be used. All the structs, except the model-editing-related ones, have their attributes public.
Direct FFI bindings are available inside the mujoco_rs::mujoco_c module.
Mixing between direct FFI bindings and the rest of MuJoCo-rs is also possible.
Some MuJoCo-rs types are direct FFI aliases, while core simulation/runtime types
(such as MjModel and MjData) are safe wrapper structs.
To obtain a reference to the FFI type inside a wrapper, call either ffi() or
unsafe ffi_mut().
For example, MjData::ffi_mut
and MjModel::ffi can be used
as arguments to mj_step.
Warning
ffi_mut() bypasses wrapper invariants. Incorrect writes through raw FFI fields can
violate safety assumptions and may cause undefined behavior.
unsafe { mujoco_rs::mujoco_c::mj_step(model.ffi(), data.ffi_mut()) }
FFI bindings can also be used to read raw attributes directly:
model.ffi().nq