wickra_embed_core/lib.rs
1//! Allocation-free, `#![no_std]` streaming technical indicators.
2//!
3//! `wickra-embed-core` runs the Wickra indicator math where there is no operating
4//! system and no heap — microcontrollers, FPGA soft-cores, HFT co-processors.
5//! Every [`Indicator`] update is O(1) with a bounded worst case, keeps its state
6//! inline in fixed-capacity buffers (no allocation), and produces the
7//! **byte-for-byte identical** value the std [`wickra-core`] library produces on
8//! a server.
9//!
10//! [`wickra-core`]: https://crates.io/crates/wickra-core
11//!
12//! # Design
13//!
14//! - **No heap.** Windowed indicators store their history in a const-generic
15//! [`Ring`](ring::Ring) or a fixed array; nothing touches an allocator. The
16//! window length is the const parameter `N` (e.g. [`Sma<20>`](Sma)).
17//! - **No panics in the update path.** A panic on a microcontroller is a reset,
18//! so the core never uses `unwrap`/`expect`/`unreachable!` on the hot path;
19//! warmup and undefined states are expressed as `None`.
20//! - **Deterministic to the bit.** The floating-point work is done in the exact
21//! same order as `wickra-core` (rolling-sum add/subtract order, the periodic
22//! reseed, the final `sum / period` division), so the result is identical on
23//! `thumbv7em-none-eabihf`, `thumbv6m-none-eabi` and an x86-64 host alike. The
24//! few transcendental ops (`abs`, `max`, fused multiply-add) route through a
25//! single [`math`] switch point — std on a host, `libm` on bare metal — whose
26//! two implementations are IEEE-754 identical.
27//!
28//! # Example
29//!
30//! ```
31//! use wickra_embed_core::{Indicator, Sma};
32//!
33//! let mut sma = Sma::<3>::new();
34//! let mut last = None;
35//! for i in 0..10 {
36//! last = sma.update(100.0 + f64::from(i));
37//! }
38//! assert!(last.is_some());
39//! ```
40
41#![cfg_attr(not(feature = "std"), no_std)]
42#![forbid(unsafe_code)]
43
44pub mod indicators;
45mod math;
46pub mod ohlcv;
47pub mod ring;
48pub mod traits;
49
50pub use indicators::{Atr, Ema, Roc, Rsi, Sma};
51pub use ohlcv::Candle;
52pub use traits::Indicator;
53
54/// Crate version string (`CARGO_PKG_VERSION`), for the C ABI and diagnostics.
55#[must_use]
56pub fn version() -> &'static str {
57 env!("CARGO_PKG_VERSION")
58}