Struct relay_cogs::FeatureWeights
source · pub struct FeatureWeights(/* private fields */);
Expand description
A collection of weighted app features.
Used to attribute a single COGS measurement to multiple features.
Implementations§
source§impl FeatureWeights
impl FeatureWeights
sourcepub fn new(feature: AppFeature) -> Self
pub fn new(feature: AppFeature) -> Self
Attributes all measurements to a single AppFeature
.
sourcepub fn builder() -> FeatureWeightsBuilder
pub fn builder() -> FeatureWeightsBuilder
Returns an FeatureWeights
builder.
sourcepub fn merge(self, other: Self) -> Self
pub fn merge(self, other: Self) -> Self
Merges two instances of FeatureWeights
and sums the contained weights.
sourcepub fn weights(&self) -> impl Iterator<Item = (AppFeature, f32)> + '_
pub fn weights(&self) -> impl Iterator<Item = (AppFeature, f32)> + '_
Returns an iterator yielding an app feature and it’s associated weight.
Weights are normalized to the total stored weights in the range between 0.0
and 1.0
.
Used to divide a measurement by the stored weights.
§Examples
use relay_cogs::{AppFeature, FeatureWeights};
use std::collections::HashMap;
let app_features = FeatureWeights::builder()
.weight(AppFeature::Transactions, 1)
.weight(AppFeature::Spans, 1)
.build();
let weights: HashMap<AppFeature, f32> = app_features.weights().collect();
assert_eq!(weights, HashMap::from([(AppFeature::Transactions, 0.5), (AppFeature::Spans, 0.5)]))
Trait Implementations§
source§impl Clone for FeatureWeights
impl Clone for FeatureWeights
source§fn clone(&self) -> FeatureWeights
fn clone(&self) -> FeatureWeights
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for FeatureWeights
impl Debug for FeatureWeights
source§impl From<AppFeature> for FeatureWeights
impl From<AppFeature> for FeatureWeights
source§fn from(value: AppFeature) -> Self
fn from(value: AppFeature) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for FeatureWeights
impl RefUnwindSafe for FeatureWeights
impl Send for FeatureWeights
impl Sync for FeatureWeights
impl Unpin for FeatureWeights
impl UnwindSafe for FeatureWeights
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)