rdf_types/interpretation/
fallible.rs

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