pub struct DynamicScoreSetBuilder<T: Float, I> { /* private fields */ }Expand description
Incremental builder for DynamicScoreSet.
Accumulates raw (weight, metric) pairs via .push(), then
normalizes them into a DynamicScoreSet via .build().
Each weight is validated on push (must be finite and > 0). Normalization happens once at build time.
§Examples
Chain construction:
ⓘ
let set = DynamicScoreSet::<f64, &str>::builder()
.push(2.0, gc_metric.boxed())?
.push(3.0, len_metric.boxed())?
.build()?;Conditional construction:
ⓘ
let mut builder = DynamicScoreSet::<f64, &str>::builder();
builder = builder.push(2.0, baseline_metric.boxed())?;
if enable_extra {
builder = builder.push(1.0, extra_metric.boxed())?;
}
let set = builder.build()?;Implementations§
Source§impl<T: Float, I> DynamicScoreSetBuilder<T, I>
impl<T: Float, I> DynamicScoreSetBuilder<T, I>
Sourcepub fn push(
self,
weight: T,
metric: Box<dyn Scorable<T, I>>,
) -> Result<Self, &'static str>
pub fn push( self, weight: T, metric: Box<dyn Scorable<T, I>>, ) -> Result<Self, &'static str>
Push a metric 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 = DynamicScoreSet::builder();
builder = builder.push(2.0, gc_metric.boxed())?;
if some_condition {
builder = builder.push(1.0, extra_metric.boxed())?;
}
let set = builder.build()?;§Errors
Returns an error if weight is zero, negative, or not finite.
Sourcepub fn build(self) -> Result<DynamicScoreSet<T, I>, &'static str>
pub fn build(self) -> Result<DynamicScoreSet<T, I>, &'static str>
Consume the builder and produce a DynamicScoreSet with normalized
weights.
§Errors
Returns an error if no members were pushed.
Auto Trait Implementations§
impl<T, I> !RefUnwindSafe for DynamicScoreSetBuilder<T, I>
impl<T, I> !Send for DynamicScoreSetBuilder<T, I>
impl<T, I> !Sync for DynamicScoreSetBuilder<T, I>
impl<T, I> !UnwindSafe for DynamicScoreSetBuilder<T, I>
impl<T, I> Freeze for DynamicScoreSetBuilder<T, I>
impl<T, I> Unpin for DynamicScoreSetBuilder<T, I>where
T: Unpin,
impl<T, I> UnsafeUnpin for DynamicScoreSetBuilder<T, I>
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