trait Flaws { type Defect; type Insufficiency; } // Provides the same functionality as core::convert::Into without a generic implementation of T: Blame, which causes conflicts. This will be deprecated when specialization is stabilized in favor of core::convert::From. trait Blame { fn blame(self) -> T; } // Provides the same functionality as core::convert::TryInto without a generic implementation of T: TryBlame, which causes conflicts. This will be deprecated when specialization is stabilized in favor of core::convert::TryFrom. trait TryBlame { type Error; fn try_blame(self) -> core::result::Result; } #[non_exhaustive] enum FaultConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom, Defect: core::convert::TryFrom >, { Insufficiency(>::Error), Defect(>::Error), } impl core::fmt::Debug for FaultConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom< W::Insufficiency, Error: core::fmt::Debug, >, Defect: core::convert::TryFrom< W::Defect, Error: core::fmt::Debug, >, >, {} impl core::fmt::Display for FaultConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom< W::Insufficiency, Error: core::fmt::Display, >, Defect: core::convert::TryFrom< W::Defect, Error: core::fmt::Display, >, >, {} #[cfg(feature = "std")] impl std::error::Error for FaultConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom< W::Insufficiency, Error: core::fmt::Debug + core::fmt::Display, >, Defect: core::convert::TryFrom< W::Defect, Error: core::fmt::Debug + core::fmt::Display, >, >, {} struct FailureConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom, Defect: core::convert::TryFrom, >; impl core::fmt::Debug for FailureConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom< W::Insufficiency, Error: core::fmt::Debug, >, Defect: core::convert::TryFrom< W::Defect, Error: core::fmt::Debug, >, >, {} impl core::fmt::Display for FailureConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom< W::Insufficiency, Error: core::fmt::Display, >, Defect: core::convert::TryFrom< W::Defect, Error: core::fmt::Display, >, >, {} #[cfg(feature = "std")] impl std::error::Error for FailureConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom< W::Insufficiency, Error: core::fmt::Debug + core::fmt::Display, >, Defect: core::convert::TryFrom< W::Defect, Error: core::fmt::Debug + core::fmt::Display, >, >, {} struct RecallConversionError where W: Flaws, F: Flaws< Insufficiency: TryFrom, Defect: TryFrom, >; impl core::fmt::Debug for RecallConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom< W::Insufficiency, Error: core::fmt::Debug, >, Defect: TryFrom< W::Defect, Error: core::fmt::Debug, >, >, G: core::fmt::Debug, {} impl core::fmt::Display for RecallConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom< W::Insufficiency, Error: core::fmt::Display, >, Defect: TryFrom< W::Defect, Error: core::fmt::Display, >, >, G: core::fmt::Display, {} #[cfg(feature = "std")] impl std::error::Error for RecallConversionError where W: Flaws, F: Flaws< Insufficiency: core::convert::TryFrom< W::Insufficiency, Error: core::fmt::Debug + core::fmt::Display, >, Defect: TryFrom< W::Defect, Error: core::fmt::Debug + core::fmt::Display, >, >, G: core::fmt::Debug + core::fmt::Display, {} #[non_exhaustive] enum Fault where F: Flaws, { Defect(F::Defect), Insufficiency(F::Insufficiency), } impl Fault where F: Flaws, { fn is_defect(&self) -> bool; } impl Blame> for Fault where F: Flaws, W: Flaws< Insufficiency: core::convert::From, Defect: core::convert::From, >, {} impl core::clone::Clone for Fault where F: Flaws< Insufficiency: core::clone::Clone, Defect: core::clone::Clone, >, {} impl core::marker::Copy for Fault where F: Flaws< Insufficiency: core::marker::Copy, Defect: core::marker::Copy, >, {} impl core::fmt::Debug for Fault where F: Flaws< Insufficiency: core::fmt::Debug, Defect: core::fmt::Debug, >, {} impl core::fmt::Display for Fault where F: Flaws< Insufficiency: core::fmt::Display, Defect: core::fmt::Display, >, {} impl core::cmp::PartialEq for Fault where F: Flaws< Insufficiency: core::cmp::PartialEq, Defect: core::cmp::PartialEq, >, {} impl TryBlame> for Fault where F: Flaws, W: Flaws< Insufficiency: core::convert::TryFrom, Defect: core::convert::TryFrom, >, { type Error = FaultConversionError; } struct Failure where F: Flaws; impl Failure where F: Flaws, { fn is_defect(&self) -> bool; } impl Blame> for Failure where F: Flaws, W: Flaws< Insufficiency: core::convert::From, Defect: core::convert::From, >, {} impl core::fmt::Debug for Failure where F: Flaws< Insufficiency: core::fmt::Debug, Defect: core::fmt::Debug, >, {} impl core::fmt::Display for Failure where F: Flaws< Insufficiency: core::fmt::Display, Defect: core::fmt::Display, >, {} #[cfg(feature = "std")] impl std::error::Error for Failure where F: Flaws< Insufficiency: core::fmt::Debug + core::fmt::Display, Defect: core::fmt::Debug + core::fmt::Display, >, {} impl core::cmp::PartialEq for Failure where F: Flaws< Insufficiency: core::cmp::PartialEq, Defect: core::cmp::PartialEq, >, {} impl TryBlame> for Failure where F: Flaws, W: Flaws< Insufficiency: core::convert::TryFrom, Defect: core::convert::TryFrom, >, { type Error = FailureConversionError; } struct Recall where F: Flaws; impl Blame> for Recall where F: Flaws, W: Flaws< Insufficiency: core::convert::From, Defect: core::convert::From, >, T: core::convert::From, {} impl core::fmt::Debug for Recall where F: Flaws< Insufficiency: core::fmt::Debug, Defect: core::fmt::Debug, >, G: core::fmt::Debug, {} impl core::fmt::Display for Recall where F: Flaws< Insufficiency: core::fmt::Display, Defect: core::fmt::Display, >, G: core::fmt::Display, {} #[cfg(feature = "std")] impl std::error::Error for Recall where F: Flaws< Insufficiency: core::fmt::Debug + core::fmt::Display, Defect: core::fmt::Debug + core::fmt::Display, >, G: core::fmt::Debug + core::fmt::Display, {} impl core::cmp::PartialEq for Recall where F: Flaws< Insufficiency: core::cmp::PartialEq, Defect: core::cmp::PartialEq, >, G: core::cmp::PartialEq, {} impl TryBlame> for Recall where F: Flaws, W: Flaws< Insufficiency: core::convert::From, Defect: core::convert::From, >, T: core::convert::From, { type Error = RecallConversionError; } type Flawless = Never; impl Flaws for Flawless { type Insufficiency = Self; type Defect = Self; } impl TryFrom for Flawless { type Error = (); } impl TryFrom for Flawless { type Error = (); } struct EmptyStock; impl core::clone::Clone for EmptyStock {} impl core::marker::Copy for EmptyStock {} impl core::fmt::Debug for EmptyStock {} impl core::default::Default for EmptyStock {} impl core::fmt::Display for EmptyStock {} impl Flaws for EmptyStock { type Insufficiency = Self; type Defect = Flawless; } impl core::ops::PartialEq for EmptyStock {} struct FullStock; impl core::clone::Clone for FullStock {} impl core::marker::Copy for FullStock {} impl core::fmt::Debug for FullStock {} impl core::default::Default for FullStock {} impl core::fmt::Display for FullStock {} impl Flaws for FullStock { type Insufficiency = Self; type Defect = Flawless; } impl core::ops::PartialEq for FullStock {} struct ProductionFlaws; impl core::fmt::Debug for ProductionFlaws {} impl Flaws for ProductionFlaws { type Insufficiency = FullStock; type Defect = D; } struct ConsumptionFlaws; impl core::fmt::Debug for ConsumptionFlaws {} impl Flaws for ConsumptionFlaws { type Insufficiency = EmptyStock; type Defect = D; } trait Agent { type Good; fn failure(&self, fault: Fault) -> Failure where F: Flaws; fn name(&self) -> alloc::string::String; } trait Producer: Agent { type Flaws: Flaws; fn force(&self, good: Self::Good) -> core::result::Result<(), Recall<::Defect, Self::Good>> where ::Defect: Flaws< Insufficiency: TryFrom<::Insufficiency>, Defect = ::Defect, >; fn force_consumptions(&self, consumer: &C) -> core::result::Result<(), Recall<::Defect, Self::Good>> where // Required for Producer to be object safe: See https://doc.rust-lang.org/reference/items/traits.html#object-safety. Self: Sized, C: Consumer, ::Defect: Flaws< Insufficiency: TryFrom<::Insufficiency>, Defect = ::Defect, >; fn produce(&self, good: Self::Good) -> core::result::Result<(), Recall>; fn produce_consumptions(&self, consumer: &C) -> core::result::Result<(), Recall> where // Required for Producer to be object safe: See https://doc.rust-lang.org/reference/items/traits.html#object-safety. Self: Sized, C: Consumer; fn recall(&self, fault: Fault, good: Self::Good) -> Recall; } trait Consumer: Agent { type Flaws: Flaws; fn consume(&self) -> core::result::Result>; fn demand(&self) -> core::result::Result::Defect>> where ::Defect: Flaws< Insufficiency: TryFrom<::Insufficiency>, Defect = ::Defect, >; } mod channel { struct WithdrawnDemand; impl core::clone::Clone for WithdrawnDemand {} impl core::marker::Copy for WithdrawnDemand {} impl core::fmt::Debug for WithdrawnDemand {} impl core::default::Default for WithdrawnDemand {} impl core::fmt::Display for WithdrawnDemand {} impl Flaws for WithdrawnDemand { type Insufficiency = Flawless; type Defect = Self; } struct WithdrawnSupply; impl core::clone::Clone for WithdrawnSupply {} impl core::marker::Copy for WithdrawnSupply {} impl core::fmt::Debug for WithdrawnSupply {} impl core::default::Default for WithdrawnSupply {} impl core::fmt::Display for WithdrawnSupply {} impl Flaws for WithdrawnSupply { type Insufficiency = Flawless; type Defect = Self; } trait InfiniteChannel { type Producer: Producer; type Consumer: Consumer>; type Args; fn establish(args: Self::Args) -> (Self::Producer, Self::Consumer); } trait FiniteChannel { type Producer: Producer>; type Consumer: Consumer>; type Args; fn establish(args: Self::Args, size: usize) -> (Self::Producer, Self::Consumer); } } mod queue { trait InfiniteQueue: Consumer + Producer { type Args; fn allocate(args: Self::Args) -> Self; } trait FiniteQueue: Consumer + Producer { type Args; fn allocate(args: Self::Args, size: usize) -> Self; } }