use std::future::Future;
use crate::types::budget::Budget;
use crate::types::error::CruxErr;
use crate::types::recovery::Recovery;
use crate::types::step::Step;
pub trait Context: Send {
fn step<F, Fut, T>(
&mut self,
name: &str,
f: F,
) -> impl Future<Output = Result<T, CruxErr>> + Send
where
F: FnOnce() -> Fut + Send,
Fut: Future<Output = Result<T, CruxErr>> + Send,
T: serde::Serialize + serde::de::DeserializeOwned + Send;
fn step_keyed<F, Fut, T, K>(
&mut self,
name: &str,
key: &K,
f: F,
) -> impl Future<Output = Result<T, CruxErr>> + Send
where
F: FnOnce() -> Fut + Send,
Fut: Future<Output = Result<T, CruxErr>> + Send,
T: serde::Serialize + serde::de::DeserializeOwned + Send,
K: serde::Serialize + Sync;
fn step_with_confidence<F, Fut, T>(
&mut self,
name: &str,
confidence: f32,
f: F,
) -> impl Future<Output = Result<T, CruxErr>> + Send
where
F: FnOnce() -> Fut + Send,
Fut: Future<Output = Result<T, CruxErr>> + Send,
T: serde::Serialize + serde::de::DeserializeOwned + Send;
fn step_retryable<F, Fut, T>(
&mut self,
name: &str,
confidence: f32,
make_fut: F,
) -> impl Future<Output = Result<T, CruxErr>> + Send
where
F: FnMut() -> Fut + Send,
Fut: Future<Output = Result<T, CruxErr>> + Send,
T: serde::Serialize + serde::de::DeserializeOwned + Send;
fn on_low_confidence<F, Fut>(&mut self, threshold: f32, handler: F)
where
F: Fn(f32) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Recovery<serde_json::Value>> + Send + 'static;
fn on_step_failure<F, Fut>(&mut self, handler: F)
where
F: Fn(CruxErr) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Recovery<serde_json::Value>> + Send + 'static;
fn on_budget_exceeded<F, Fut>(&mut self, handler: F)
where
F: Fn(Budget) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Recovery<serde_json::Value>> + Send + 'static;
fn set_max_retries(&mut self, n: u32);
fn set_budget(&mut self, budget: Budget);
fn consume_budget(&mut self, amount: u64);
fn budget(&self) -> &Budget;
fn remaining_budget(&self) -> u64;
fn step_count(&self) -> u32;
fn snapshot_steps(&self) -> &[Step];
fn step_stream<F, S, T>(
&mut self,
name: &str,
f: F,
) -> impl Future<Output = Result<T, CruxErr>> + Send
where
F: FnOnce() -> S + Send,
S: futures::Stream<Item = Result<T, CruxErr>> + Send + Unpin,
T: serde::Serialize + serde::de::DeserializeOwned + Send;
}