Skip to main content

Module potential

Module potential 

Source
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

  1. The C++ side creates a potential object (e.g., LJPot).
  2. A trampoline function with the PotentialCallback signature is registered, casting user_data back to the concrete type and calling forceImpl.
  3. The Rust core dispatches through the function pointer, receiving results via the rgpot_force_out_t output struct.

§Lifetime Contract

  • The user_data pointer is borrowed by PotentialImpl. The caller must keep the underlying object alive for the lifetime of the handle.
  • If a free_fn is provided, it is called on drop when user_data is non-null, transferring ownership to PotentialImpl.
  • The handle is exposed to C as rgpot_potential_t — an opaque pointer managed via rgpot_potential_new / rgpot_potential_free.

Structs§

PotentialImpl
Opaque potential handle wrapping a callback + user data.

Type Aliases§

FreeFn
Destructor for the user_data pointer.
PotentialCallback
Function pointer type for a potential energy calculation.
rgpot_potential_t
Opaque handle exposed to C as rgpot_potential_t.