Struct scientisto::async_experiment::AsyncExperiment
source · pub struct AsyncExperiment { /* private fields */ }
Expand description
async
Experiment
Basic struct defining the conducted async
experiment. Initialized using type definitions instead of
allocations. The AsyncExperiment
is a consumable, once executed, it will consume the constituent
futures defined for the experiment.
The results of the async
experiment, if run and awaited, are input into the publisher. The default
publisher is a noop
, whereas a custom publisher can be used either as a passed function or
closure. Publisher can contain any logic, as long as it returns a Unit
type.
Operation
- decides whether or not to run the experiment block
- swallows and records exceptions raised in the try block when overriding raised
- publishes all this information
Panics
If any of the constituent futures panics
Errors
None
Safety
No unsafe
code is executed outside the std
usage.
Examples
Using function callbacks
use scientisto::{AsyncExperiment,Observation};
async fn production() -> f32 { 3.00 }
async fn alternative() -> f32 { 3.02 }
async_std::task::block_on(async {
AsyncExperiment::new("Using callback functions")
.control(production())
.experiment(alternative())
.publish(|o: &Observation<f32, f32>| assert!(!o.is_matching()))
.run().await;
})
Using closures
use scientisto::{AsyncExperiment,Observation};
use tracing::info;
async_std::task::block_on(async {
AsyncExperiment::new("Test")
.control(async { 3.0 })
.experiment(async { 3.0 })
.publish(|o: &Observation<f32, f32>| {
assert!(o.is_matching());
info!("Any logic, including side effects, can be here!")
})
.run().await;
})
Implementations§
Trait Implementations§
source§impl Clone for AsyncExperiment
impl Clone for AsyncExperiment
source§fn clone(&self) -> AsyncExperiment
fn clone(&self) -> AsyncExperiment
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 moreAuto Trait Implementations§
impl RefUnwindSafe for AsyncExperiment
impl Send for AsyncExperiment
impl Sync for AsyncExperiment
impl Unpin for AsyncExperiment
impl UnwindSafe for AsyncExperiment
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