pub struct FiniteScoreSetBuilder<T: Float, I, E> { /* private fields */ }Expand description
Incremental builder for FiniteScoreSet.
Accumulates raw (weight, variant) pairs via .push(), then
normalizes them into a FiniteScoreSet via .build().
Each weight is validated on push (must be finite and > 0). Normalization happens once at build time.
§Examples
Chain construction:
ⓘ
let set = FiniteScoreSet::<f64, &str, TestKind<f64, &str>>::builder()
.push(2.0, TestKind::AlwaysZero(const_metric("zero", 0.0)))?
.push(3.0, TestKind::AlwaysOne(const_metric("one", 1.0)))?
.build()?;Conditional construction:
ⓘ
let mut builder = FiniteScoreSet::<f64, &str, TestKind<f64, &str>>::builder();
builder = builder.push(2.0, baseline_variant)?;
if enable_extra {
builder = builder.push(1.0, extra_variant)?;
}
let set = builder.build()?;Implementations§
Source§impl<T: Float, I, E: Scorable<T, I>> FiniteScoreSetBuilder<T, I, E>
impl<T: Float, I, E: Scorable<T, I>> FiniteScoreSetBuilder<T, I, E>
Sourcepub fn push(self, weight: T, variant: E) -> Result<Self, &'static str>
pub fn push(self, weight: T, variant: E) -> Result<Self, &'static str>
Push a metric enum variant with a raw weight into the builder.
The weight must be finite and strictly positive. This is validated
immediately (fail-fast). Takes and returns Self for chaining.
For incremental construction, rebind the result:
ⓘ
let mut builder = FiniteScoreSet::builder();
builder = builder.push(2.0, variant_a)?;
if some_condition {
builder = builder.push(1.0, variant_b)?;
}
let set = builder.build()?;§Errors
Returns an error if weight is zero, negative, or not finite.
Sourcepub fn build(self) -> Result<FiniteScoreSet<T, I, E>, &'static str>
pub fn build(self) -> Result<FiniteScoreSet<T, I, E>, &'static str>
Consume the builder and produce a FiniteScoreSet with normalized
weights.
§Errors
Returns an error if no members were pushed.
Auto Trait Implementations§
impl<T, I, E> Freeze for FiniteScoreSetBuilder<T, I, E>
impl<T, I, E> RefUnwindSafe for FiniteScoreSetBuilder<T, I, E>
impl<T, I, E> Send for FiniteScoreSetBuilder<T, I, E>
impl<T, I, E> Sync for FiniteScoreSetBuilder<T, I, E>
impl<T, I, E> Unpin for FiniteScoreSetBuilder<T, I, E>
impl<T, I, E> UnsafeUnpin for FiniteScoreSetBuilder<T, I, E>
impl<T, I, E> UnwindSafe for FiniteScoreSetBuilder<T, I, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more