Skip to main content

bast3st_eval/evaluation/selectable/
sel_merge.rs

1use std::borrow::Cow;
2
3use crate::{evaluation::SelectableSource, spec::FatalError};
4
5impl<A: SelectableSource, B: SelectableSource> SelectableSource for (A, B) {
6    async fn request<'z>(
7        &'z self,
8        selector: &crate::spec::Selector,
9        allowed_features: crate::Features,
10    ) -> Result<Cow<'z, crate::spec::RuntimeAny>, FatalError> {
11        match self.0.request(selector, allowed_features).await {
12            Err(FatalError::RequestedSelectorValueNotAvailable(_)) => {
13                self.1.request(selector, allowed_features).await
14            }
15            x => x,
16        }
17    }
18}
19
20impl<A: SelectableSource, B: SelectableSource, C: SelectableSource> SelectableSource for (A, B, C) {
21    async fn request<'z>(
22        &'z self,
23        selector: &crate::spec::Selector,
24        allowed_features: crate::Features,
25    ) -> Result<Cow<'z, crate::spec::RuntimeAny>, FatalError> {
26        match self.0.request(selector, allowed_features).await {
27            Err(FatalError::RequestedSelectorValueNotAvailable(_)) => {
28                match self.1.request(selector, allowed_features).await {
29                    Err(FatalError::RequestedSelectorValueNotAvailable(_)) => {
30                        self.2.request(selector, allowed_features).await
31                    }
32                    x => x,
33                }
34            }
35            x => x,
36        }
37    }
38}