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§

source§

impl AsyncExperiment

source

pub fn new(name: &'static str) -> Self

source

pub fn name(&self) -> &'static str

source

pub fn control<T, F>(self, f: F) -> AsyncControlOnly<T, F>where F: Future<Output = T>,

Trait Implementations§

source§

impl Clone for AsyncExperiment

source§

fn clone(&self) -> AsyncExperiment

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for AsyncExperiment

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.