Expand description
Callback-based potential dispatch.
This module defines PotentialImpl, an opaque handle that wraps a C
function pointer callback together with a void* user_data and an optional
destructor. This is the core abstraction that lets existing C++ potentials
(LJ, CuH2, or any future implementation) plug into the Rust infrastructure
without the Rust side knowing the concrete type.
§How it Works
- The C++ side creates a potential object (e.g.,
LJPot). - A trampoline function with the
PotentialCallbacksignature is registered, castinguser_databack to the concrete type and callingforceImpl. - The Rust core dispatches through the function pointer, receiving results
via the
rgpot_force_out_toutput struct.
§Lifetime Contract
- The
user_datapointer is borrowed byPotentialImpl. The caller must keep the underlying object alive for the lifetime of the handle. - If a
free_fnis provided, it is called on drop whenuser_datais non-null, transferring ownership toPotentialImpl. - The handle is exposed to C as
rgpot_potential_t— an opaque pointer managed viargpot_potential_new/rgpot_potential_free.
Structs§
- Potential
Impl - Opaque potential handle wrapping a callback + user data.
Type Aliases§
- FreeFn
- Destructor for the user_data pointer.
- Potential
Callback - Function pointer type for a potential energy calculation.
- rgpot_
potential_ t - Opaque handle exposed to C as
rgpot_potential_t.