Skip to main content

object_rainbow/extras/
fetch_extra.rs

1use crate::*;
2
3pub trait ParseFetch<E: 'static + Clone>: Sized {
4    fn parse_fetch<I: PointInput<Extra: Fetch<T = E>>>(input: I) -> Result<Self>;
5}
6
7pub trait ParseFetchInline<E: 'static + Clone>: ParseFetch<E> {
8    fn parse_fetch_inline<I: PointInput<Extra: Fetch<T = E>>>(input: &mut I) -> Result<Self>;
9
10    fn parse_fetch_as_inline<I: PointInput<Extra: Fetch<T = E>>>(input: I) -> Result<Self> {
11        input.parse_as_inline(Self::parse_fetch_inline)
12    }
13}
14
15#[derive(Debug, Clone, PartialEq, Eq, ToOutput, Tagged, ListHashes, Topological, Size)]
16pub struct FetchExtra<F>(pub F);
17
18impl<
19    E: 'static + Clone,
20    F: ParseFetch<E>,
21    X: 'static + Clone + Fetch<T = E>,
22    I: PointInput<Extra = X>,
23> Parse<I> for FetchExtra<F>
24{
25    fn parse(input: I) -> crate::Result<Self> {
26        F::parse_fetch(input).map(Self)
27    }
28}
29
30impl<
31    E: 'static + Clone,
32    F: ParseFetchInline<E>,
33    X: 'static + Clone + Fetch<T = E>,
34    I: PointInput<Extra = X>,
35> ParseInline<I> for FetchExtra<F>
36{
37    fn parse_inline(input: &mut I) -> crate::Result<Self> {
38        F::parse_fetch_inline(input).map(Self)
39    }
40}