ferritin_core/trajectory/mod.rs
1//! Trajectory layer (Layer 2): multi-model structure access.
2//!
3//! This module provides the [`Trajectory`] trait for accessing ordered
4//! collections of [`Model`] frames, plus two implementations:
5//!
6//! - [`ArrayTrajectory`]: eager — stores all frames as `Vec<Model>`.
7//! - [`ModelCoordsTrajectory`]: lazy — stores one topology + `Coordinates`.
8//!
9//! All implementations are object-safe (`dyn Trajectory` works).
10
11use std::borrow::Cow;
12use crate::model::Model;
13
14pub mod array_trajectory;
15pub mod coordinates;
16pub mod model_coords_trajectory;
17
18pub use array_trajectory::ArrayTrajectory;
19pub use coordinates::{Coordinates, Frame, UnitCell};
20pub use model_coords_trajectory::ModelCoordsTrajectory;
21
22/// Multi-model structure access. Object-safe: usable as `dyn Trajectory`.
23///
24/// Implementors expose an ordered sequence of [`Model`] frames. Frames may be
25/// returned as borrowed references (`Cow::Borrowed`) when already in memory, or
26/// as owned values (`Cow::Owned`) when constructed lazily.
27pub trait Trajectory {
28 /// Total number of frames in the trajectory.
29 fn frame_count(&self) -> usize;
30
31 /// A representative frame (typically the first), useful when callers need
32 /// topology access without specifying a frame index.
33 fn representative(&self) -> &Model;
34
35 /// Returns the frame at `index`, either borrowed or constructed on demand.
36 ///
37 /// # Panics
38 /// Panics if `index >= frame_count()`.
39 fn frame(&self, index: usize) -> Cow<'_, Model>;
40}
41
42// Compile-time object-safety check — must compile:
43fn _assert_object_safe(_: &dyn Trajectory) {}