1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
use super::{GenerativeInterpretation, Interpretation}; use crate::utils::InfallibleIterator; pub trait FallibleInterpretation { type Resource; type Error; } impl<I: Interpretation> FallibleInterpretation for I { type Resource = I::Resource; type Error = std::convert::Infallible; } pub trait TraversableFallibleInterpretation: FallibleInterpretation { type Resources<'a>: Iterator<Item = Result<&'a Self::Resource, Self::Error>> where Self: 'a; fn try_resources(&self) -> Self::Resources<'_>; } impl<I: super::TraversableInterpretation> TraversableFallibleInterpretation for I { type Resources<'a> = InfallibleIterator<I::Resources<'a>> where Self: 'a; fn try_resources(&self) -> Self::Resources<'_> { InfallibleIterator(self.resources()) } } pub trait FallibleGenerativeInterpretation: FallibleInterpretation { fn try_new_resource(&mut self) -> Result<Self::Resource, Self::Error>; } impl<I: GenerativeInterpretation> FallibleGenerativeInterpretation for I { fn try_new_resource(&mut self) -> Result<Self::Resource, Self::Error> { Ok(self.new_resource()) } }