score_set/lib.rs
1//! # score-set
2//!
3//! A Rust library for building **weighted scoring operators** as composable
4//! closures.
5//!
6//! Define metrics via a builder pipeline, combine them with weights, and
7//! produce a closure — either a weighted sum function or a breakdown iterator.
8//! The downstream caller only sees `impl Fn(&C) -> Score` or
9//! `impl Fn(&C) -> Vec<Breakdown>`.
10//!
11//! # Quick example
12//!
13//! ```ignore
14//! use score_set::*;
15//!
16//! struct DnaCtx<'a> {
17//! dna: &'a str,
18//! len: usize,
19//! }
20//!
21//! let gc = metric32("gc")
22//! .measure()
23//! .by(|ctx: &DnaCtx| gc_ratio(ctx.dna) as f32)
24//! .map01()
25//! .identity();
26//!
27//! let len = metric32("len")
28//! .measure()
29//! .by(|ctx: &DnaCtx| ctx.len as f32)
30//! .map01()
31//! .linear(100.0);
32//!
33//! let scorer = ScoreSet32::new()
34//! .push(2.0, gc)?
35//! .push(1.0, len)?
36//! .sum()?;
37//!
38//! let ctx = DnaCtx { dna: "ACGTACGT", len: 8 };
39//! let total = scorer(&ctx);
40//! # Ok::<(), &'static str>(())
41//! ```
42//!
43//! # no_std
44//!
45//! This crate is `#![no_std]` with `extern crate alloc` — it only needs
46//! `Vec` and `String` from the allocator and works on bare-metal targets.
47
48#![no_std]
49extern crate alloc;
50
51#[cfg(test)]
52extern crate std;
53
54// Three-state precision selection:
55// default → f32 only (ScoreSet32, Metric32, … at crate root)
56// f64 → f64 only (ScoreSet64, Metric64, … at crate root)
57// f64 + both → f32 + f64 (ScoreSet32 + ScoreSet64 at crate root)
58// All modules are private — users only depend on re-exported types.
59
60#[cfg(not(feature = "f64"))]
61mod metric_f32;
62#[cfg(not(feature = "f64"))]
63pub use metric_f32::*;
64
65#[cfg(all(feature = "f64", not(feature = "both")))]
66mod metric_f64;
67#[cfg(all(feature = "f64", not(feature = "both")))]
68pub use metric_f64::*;
69
70#[cfg(all(feature = "f64", feature = "both"))]
71mod metric_f32;
72#[cfg(all(feature = "f64", feature = "both"))]
73mod metric_f64;
74#[cfg(all(feature = "f64", feature = "both"))]
75pub use metric_f32::*;
76#[cfg(all(feature = "f64", feature = "both"))]
77pub use metric_f64::*;
78
79mod value;
80pub use value::{GtZero, NormalizedContainer, NormalizedWeight, ScoreOps, Value01};
81pub use witnessed::{WitnessExt, Witnessed};
82
83#[cfg(test)]
84mod test_support;