librebound-sys 4.6.0

Raw FFI bindings and safe RAII wrappers for the REBOUND N-body integrator
Documentation
//! Raw FFI bindings and safe RAII wrappers for REBOUND.
//!
//! REBOUND is a C N-body integration library. This crate exposes the
//! underlying C API as:
//!
//! - [`ffi`]: raw `extern "C"` bindings to REBOUND functions + types.
//! - [`Simulation`]: thin, allocation-owning RAII wrapper around
//!   `reb_simulation`.
//! - [`IntegratorConfig`] + [`Ias15AdaptiveMode`]: ergonomic types for IAS15
//!   timestep + adaptive-mode configuration.
//!
//! This crate contains no domain logic (ephemerides, orbital elements,
//! observatories, etc.) and no dependencies on ASSIST. The companion
//! `libassist-sys` crate layers ASSIST's ephemeris-driven forces on top.

pub mod ffi;
mod wrappers;

pub use wrappers::{Ias15AdaptiveMode, IntegratorConfig, Simulation};

/// Errors produced by the low-level REBOUND FFI wrappers.
///
/// Covers REBOUND integration-exit conditions. Higher-level errors (ASSIST
/// ephemeris failures, light-time convergence, etc.) live in downstream
/// crates that wrap this type via `#[from]`.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// Integration ended early because no particles remain (`REB_STATUS_NO_PARTICLES`).
    #[error("integration ended: no particles remain in the simulation")]
    NoParticles,

    /// Integration ended early because two particles had a close encounter
    /// (`REB_STATUS_ENCOUNTER`; triggered by `exit_min_distance`).
    #[error("integration ended: close encounter")]
    CloseEncounter,

    /// Integration ended early because a particle escaped
    /// (`REB_STATUS_ESCAPE`; triggered by `exit_max_distance`).
    #[error("integration ended: particle escape")]
    Escape,

    /// Integration ended early because two particles collided
    /// (`REB_STATUS_COLLISION`).
    #[error("integration ended: collision")]
    Collision,

    /// REBOUND returned a generic/unknown error status.
    ///
    /// Holds the raw `REB_STATUS` code for diagnostics; use the named variants
    /// above to match on the common integration-exit conditions.
    #[error("REBOUND integration failed with status {0}")]
    IntegrationFailed(i32),

    #[error("{0}")]
    Other(String),
}

pub type Result<T> = std::result::Result<T, Error>;