Skip to main content

CombinatorExt

Trait CombinatorExt 

Source
pub trait CombinatorExt:
    DurationSampler
    + Sized
    + 'static {
    // Provided methods
    fn boxed(self) -> Box<dyn DurationSampler> { ... }
    fn boxed_clonable(self) -> Box<dyn ClonableDurationSampler>
       where Self: Clone + Send + Sync { ... }
    fn map<F>(self, f: F) -> MapSampler<Self, F>
       where F: FnMut(&mut dyn Rng, SimTime, f64) -> f64 { ... }
    fn delay(self, delay: Box<dyn DurationSampler>) -> DelaySampler<Self> { ... }
    fn jitter(self, jitter: Box<dyn DurationSampler>) -> JitterSampler<Self> { ... }
    fn chain<F>(
        self,
        sampler: Box<dyn DurationSampler>,
        f: F,
    ) -> ChainSampler<Self, F>
       where F: FnMut(&mut dyn Rng, SimTime, f64, f64) -> f64 { ... }
    fn aggregate<F>(
        self,
        others: impl IntoIterator<Item = Box<dyn DurationSampler>>,
        f: F,
    ) -> AggregateSampler<F>
       where F: FnMut(&mut dyn Rng, SimTime, Vec<f64>) -> f64 { ... }
    fn aggregate_builder(self) -> AggregateBuilder { ... }
    fn clamp(self, min: f64, max: f64) -> ClampSampler<Self> { ... }
    fn ensure_non_negative<F>(
        self,
        limit_try_count: u8,
        fallback: F,
    ) -> EnsureNonNegativeSampler<Self, F>
       where F: FnMut(&mut dyn Rng, SimTime) -> Duration { ... }
}
Expand description

An extension trait for DurationSampler that provides fluent combinator methods for creating and composing complex duration sampling logic.

Provided Methods§

Source

fn boxed(self) -> Box<dyn DurationSampler>

Boxes the sampler into a Box<dyn DurationSampler> to erase its concrete type.

Source

fn boxed_clonable(self) -> Box<dyn ClonableDurationSampler>
where Self: Clone + Send + Sync,

Boxes the sampler as a cloneable trait object. Requires the underlying sampler to be Clone, Send, and Sync.

Source

fn map<F>(self, f: F) -> MapSampler<Self, F>
where F: FnMut(&mut dyn Rng, SimTime, f64) -> f64,

Transforms the output of this sampler using the provided closure f.

Source

fn delay(self, delay: Box<dyn DurationSampler>) -> DelaySampler<Self>

Adds a delay to the result of this sampler using another sampler for the duration.

Source

fn jitter(self, jitter: Box<dyn DurationSampler>) -> JitterSampler<Self>

Adds a jitter (noise) to the result of this sampler using another sampler for the variation.

Source

fn chain<F>( self, sampler: Box<dyn DurationSampler>, f: F, ) -> ChainSampler<Self, F>
where F: FnMut(&mut dyn Rng, SimTime, f64, f64) -> f64,

Chains this sampler with another, combining their outputs using the provided closure f.

Source

fn aggregate<F>( self, others: impl IntoIterator<Item = Box<dyn DurationSampler>>, f: F, ) -> AggregateSampler<F>
where F: FnMut(&mut dyn Rng, SimTime, Vec<f64>) -> f64,

Aggregates the results of this sampler and a collection of others into a single value using the provided closure f.

Source

fn aggregate_builder(self) -> AggregateBuilder

Returns an AggregateBuilder initialized with this sampler, allowing for a more flexible construction of aggregate samplers.

Source

fn clamp(self, min: f64, max: f64) -> ClampSampler<Self>

Clamps the output of this sampler within the range [min, max].

Source

fn ensure_non_negative<F>( self, limit_try_count: u8, fallback: F, ) -> EnsureNonNegativeSampler<Self, F>
where F: FnMut(&mut dyn Rng, SimTime) -> Duration,

Ensures the sampled duration is non-negative.

If the value remains negative after limit_try_count attempts, the fallback closure is invoked.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: DurationSampler + Sized + 'static> CombinatorExt for T