librebound_sys/lib.rs
1//! Raw FFI bindings and safe RAII wrappers for REBOUND.
2//!
3//! REBOUND is a C N-body integration library. This crate exposes the
4//! underlying C API as:
5//!
6//! - [`ffi`]: raw `extern "C"` bindings to REBOUND functions + types.
7//! - [`Simulation`]: thin, allocation-owning RAII wrapper around
8//! `reb_simulation`.
9//! - [`IntegratorConfig`] + [`Ias15AdaptiveMode`]: ergonomic types for IAS15
10//! timestep + adaptive-mode configuration.
11//!
12//! This crate contains no domain logic (ephemerides, orbital elements,
13//! observatories, etc.) and no dependencies on ASSIST. The companion
14//! `libassist-sys` crate layers ASSIST's ephemeris-driven forces on top.
15
16pub mod ffi;
17mod wrappers;
18
19pub use wrappers::{Ias15AdaptiveMode, IntegratorConfig, Simulation};
20
21/// Errors produced by the low-level REBOUND FFI wrappers.
22///
23/// Covers REBOUND integration-exit conditions. Higher-level errors (ASSIST
24/// ephemeris failures, light-time convergence, etc.) live in downstream
25/// crates that wrap this type via `#[from]`.
26#[derive(Debug, thiserror::Error)]
27pub enum Error {
28 /// Integration ended early because no particles remain (`REB_STATUS_NO_PARTICLES`).
29 #[error("integration ended: no particles remain in the simulation")]
30 NoParticles,
31
32 /// Integration ended early because two particles had a close encounter
33 /// (`REB_STATUS_ENCOUNTER`; triggered by `exit_min_distance`).
34 #[error("integration ended: close encounter")]
35 CloseEncounter,
36
37 /// Integration ended early because a particle escaped
38 /// (`REB_STATUS_ESCAPE`; triggered by `exit_max_distance`).
39 #[error("integration ended: particle escape")]
40 Escape,
41
42 /// Integration ended early because two particles collided
43 /// (`REB_STATUS_COLLISION`).
44 #[error("integration ended: collision")]
45 Collision,
46
47 /// REBOUND returned a generic/unknown error status.
48 ///
49 /// Holds the raw `REB_STATUS` code for diagnostics; use the named variants
50 /// above to match on the common integration-exit conditions.
51 #[error("REBOUND integration failed with status {0}")]
52 IntegrationFailed(i32),
53
54 #[error("{0}")]
55 Other(String),
56}
57
58pub type Result<T> = std::result::Result<T, Error>;