use rand::{thread_rng, Rng};
pub mod simulation_results;
pub use simulation_results::SimulationResult;
mod n_iterations_simulator;
use n_iterations_simulator::NIterationsSimulator;
mod n_events_simulator;
use n_events_simulator::NEventsSimulator;
pub mod erasure;
pub use erasure::*;
pub trait Decoder: Send + Sync + Sized {
type Code;
type Error;
type Result: DecodingResult;
fn for_code(self, code: Self::Code) -> Self;
fn take_code(&mut self) -> Self::Code;
fn decode(&self, error: &Self::Error) -> Self::Result;
fn get_random_error_with_rng<R: Rng>(&self, rng: &mut R) -> Self::Error;
fn get_random_error(&self) -> Self::Error {
self.get_random_error_with_rng(&mut thread_rng())
}
fn decode_random_error_with_rng<R: Rng>(&self, rng: &mut R) -> Self::Result {
self.decode(&self.get_random_error_with_rng(rng))
}
fn decode_random_error(&self) -> Self::Result {
self.decode_random_error_with_rng(&mut thread_rng())
}
fn simulate_n_iterations_with_rng<R: Rng>(
&self,
n_iterations: usize,
rng: &mut R,
) -> SimulationResult {
NIterationsSimulator::from(self)
.simulate_n_iterations_with_rng(n_iterations, rng)
.get_result()
}
fn simulate_n_iterations(&self, n_iterations: usize) -> SimulationResult {
self.simulate_n_iterations_with_rng(n_iterations, &mut thread_rng())
}
fn simulate_until_n_events_are_found_with_rng<R: Rng>(
&self,
n_events: usize,
rng: &mut R,
) -> SimulationResult {
NEventsSimulator::from(self)
.simulate_until_n_events_are_found_with_rng(n_events, rng)
.get_result()
}
fn simulate_until_n_events_are_found(&self, n_events: usize) -> SimulationResult {
self.simulate_until_n_events_are_found_with_rng(n_events, &mut thread_rng())
}
}
pub trait DecodingResult: Send + Sync {
fn is_success(&self) -> bool;
fn is_failure(&self) -> bool {
!self.is_success()
}
}