Skip to content

no_std and Embedded

stone edited this page Nov 13, 2026 · 10 revisions

no_std and embedded

Features

Feature Default Effect
std yes impl std::error::Error, the CLI binaries, file loading helpers
mcp no builds stkcraft-mcp; implies std and serde_json
(none) — no_std + alloc; the library is available, binaries are skipped
# no_std with alloc
stkcraft-time = { version = "0.2.1", default-features = false }

What is guaranteed in no_std

  • #![forbid(unsafe_code)] applies to every build. There is no unsafe to audit.
  • Epoch and duration arithmetic is integer-based (i64 seconds plus nanoseconds, with i128 totals in checked paths). No floating-point accumulation is used for time arithmetic.
  • Floating-point math goes through libm: sin, cos, floor, round, abs, to_radians. No std-only float methods are used, including powi.
  • All parsing (LSK, SCLK, EOP text) works on &str and alloc types. File I/O is the caller's responsibility.
  • Formatting uses alloc::string::String; there is no std::io in the library.

What requires std

  • Reading files for you (LeapSecondTable::from_lsk takes text; loading it from disk is your code).
  • The binaries: sclk-check, ut1-check, tdb-compare, wgc-compare.
  • The MCP server.

Tested targets

Target Status
x86_64 / aarch64 (host) full test suite
wasm32-unknown-unknown cargo build --no-default-features
thumbv7em-none-eabi cargo build --no-default-features
Rust 1.75 (MSRV) cargo check --all-targets --features mcp
cargo build --no-default-features
cargo build --no-default-features --target wasm32-unknown-unknown
cargo build --no-default-features --target thumbv7em-none-eabi
cargo +1.75.0 check --all-targets --features mcp

Sizing notes

  • The IAU DTDB table is 787 [f64; 3] rows (about 18 KiB of constants) and is always compiled in. It is the largest static table in the crate.
  • The bundled naif0012.tls is included as text and parsed at run time by LeapSecondTable::builtin(). On a resource-constrained target, parse it once at start-up and keep the LeapSecondTable.

Embedded pattern

use stkcraft_time::calendar::Calendar;
use stkcraft_time::convert::utc_to_tai;
use stkcraft_time::{LeapSecondTable, UtcDateTime};

static LSK_TEXT: &str = include_str!("../kernels/naif0012.tls");

let lsk = LeapSecondTable::from_lsk(LSK_TEXT)?;      // once, at start-up
let tai = utc_to_tai(&utc, Calendar::Gregorian, &lsk)?; // per sample

The conversion itself allocates nothing beyond the parsed table.

Clone this wiki locally