use std::fmt;
use rand::Rng;
mod binary_symmetric_channel;
pub use binary_symmetric_channel::BinarySymmetricChannel;
mod depolarizing;
pub use depolarizing::DepolarizingNoise;
mod erasure;
pub use erasure::ErasureChannel;
pub trait NoiseModel {
type Error;
fn sample_error_of_length<R: Rng>(&self, length: usize, rng: &mut R) -> Self::Error;
}
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct Probability(f64);
impl Probability {
pub fn new(probability: f64) -> Self {
Self::try_new(probability).expect("probability is not between 0 and 1")
}
pub fn try_new(probability: f64) -> Option<Self> {
if (0.0..=1.0).contains(&probability) {
Some(Self(probability))
} else {
None
}
}
pub fn value(&self) -> f64 {
self.0
}
}
impl fmt::Display for Probability {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.value())
}
}