Skip to main content

ScoreSet32

Struct ScoreSet32 

Source
pub struct ScoreSet32<C> { /* private fields */ }
Expand description

Builder for a weighted set of Metric32s.

ScoreSet32 collects metrics with raw weights, normalizes them, and produces a closure — either a weighted-sum function or a breakdown iterator.

§Examples

let scorer = ScoreSet32::new()
    .push(2.0, gc_metric)?
    .push(1.0, len_metric)?
    .sum()?;

let total: f32 = scorer(&ctx);

Implementations§

Source§

impl<C> ScoreSet32<C>

Source

pub fn new() -> Self

Create an empty score set builder.

Source

pub fn push( self, weight: f32, metric: Metric32<C>, ) -> Result<Self, &'static str>

Add a metric with a raw (unnormalized) weight.

The weight must be finite and strictly positive. Normalization happens when sum or breakdown is called.

Source

pub fn sum(self) -> Result<impl Fn(&C) -> f32, &'static str>

Consume the builder and return a weighted-sum closure.

Normalizes all weights so they sum to 1, then returns a closure impl Fn(&C) -> f32 that evaluates every metric against the context and returns the weighted sum.

§Errors

Returns an error if the set is empty or if weight normalization fails.

Source

pub fn breakdown( self, ctx: &C, ) -> Result<impl IntoIterator<Item = Breakdown32>, &'static str>

Consume the builder and return per-metric Breakdown32 rows.

Normalizes all weights so they sum to 1, evaluates every metric against ctx, and returns the result as impl IntoIterator. The returned value owns all data — no lifetime coupling to ctx — so it can be passed out of local scopes freely.

Use directly in a for loop or call .into_iter().

§Errors

Returns an error if the set is empty or if weight normalization fails.

Trait Implementations§

Source§

impl<C> Default for ScoreSet32<C>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<C> Freeze for ScoreSet32<C>

§

impl<C> RefUnwindSafe for ScoreSet32<C>

§

impl<C> Send for ScoreSet32<C>

§

impl<C> Sync for ScoreSet32<C>

§

impl<C> Unpin for ScoreSet32<C>

§

impl<C> UnsafeUnpin for ScoreSet32<C>

§

impl<C> UnwindSafe for ScoreSet32<C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WitnessExt for T

Source§

fn witness(self) -> Witnessing<Self>