Changes from MuJoCo¶
MuJoCo-rs tries to follow the MuJoCo’s API with a few exceptions that make it more Rust-idiomatic, safer and easier to use.
Methods¶
One of the changes from the MuJoCo C API are methods. Since most MuJoCo functions directly correspond to some struct, we turned those functions into methods at appropriate structs, while leaving the more general functions wrapped in idiomatic Rust function wrappers.
For example, the function mujoco_c::mj_loadXML is replaced with the method MjModel::from_xml, while the more general function mujoco_c::mju_rayGeom is replaced with utility::mju_ray_geom.
Structs¶
Most of MuJoCo’s structs are plain data structs. In Rust, we mostly keep them as-is, renaming them to PascalCase. Structs with heap-allocated data are wrapped in safe Rust types that automatically manage memory and provide safe attribute access.
Attributes not directly exposed can be accessed via .ffi() and .ffi_mut() methods.
For more details, see Interface to C API.
Additionally, MjData and MjModel provide Attribute views to specific item types (joint, body, geom, etc.).