Tempa
A no_std library for working with time in animation and real-time systems.
It provides a small set of temporal primitives: time, duration, time ranges, frame rates, and frame-based stepping. Designed around deterministic conversion between continuous time and discrete frame indices.
This makes it suitable for animation systems, simulations, and engine tooling where frame-accurate behavior matters.
Status
⚠️ Experimental / Work in Progress
The API is still evolving and may change significantly.
Features
- no_std compatible
- Time and Duration types
- Frame rate representation
- Time ranges and range operations
- Deterministic frame <-> time conversion
- Frame-based stepping utilities
Usage
std
= "0.1.4"
no_std
= { = "0.1.4", = false }
Example
// Create a frame stepper running at 60 FPS and a simple 10-second clip.
let rate = from_fps;
let mut stepper = new;
let clip = new;
// Advance the playhead by 120 frames (2 seconds at 60 FPS).
stepper.step;
assert_eq!;
assert_abs_diff_eq!;
// Convert explicitly between discrete frames and continuous time.
let frame = frame_from_time;
assert_eq!;
let time = time_from_frame;
assert_abs_diff_eq!;
// Seek to an arbitrary time. Times between frame boundaries are rounded
// down to the frame currently containing that instant.
stepper.seek_time;
assert_eq!;
assert_abs_diff_eq!;
// Normalize the playhead position within the clip.
let u = clip.normalize_time;
assert_abs_diff_eq!;
// Remap the same normalized position into another time range.
let outro = new;
let outro_time = clip.remap_time;
assert_abs_diff_eq!;
// Construct ranges directly from scalar seconds.
let window: = .into;
assert_abs_diff_eq!;
// Merge overlapping ranges, for example when combining timeline edits.
let a = new;
let b = new;
let merged = a.union;
assert_eq!;
// Stepping past the beginning of the timeline saturates at frame zero.
stepper.step;
assert_eq!;
assert_abs_diff_eq!;
License
The Tempa project is licensed under either the Apache License, Version 2.0 or the MIT license, at your option.
See LICENSE-APACHE and LICENSE-MIT for details.