bast3st_eval/evaluation/selectable/
source_rundata.rs1use std::borrow::Cow;
2
3use serde::{Deserialize, Serialize};
4
5use crate::spec::{Array, Coremapping, RealMapping, RuntimeAny, Selector};
6
7use super::{Features, SelectableSource};
8
9#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
10pub struct Rundata {
11 input: RuntimeAny, output: RuntimeAny, randoms: RuntimeAny, lists: RuntimeAny, variables: RuntimeAny, }
17
18impl Rundata {
19 pub fn new(
20 input: impl Into<Array>,
21 output: impl Into<Array>,
22 randoms: impl Into<Array>,
23 lists: impl Into<RealMapping>,
24 variables: impl Into<RealMapping>,
25 ) -> Self {
26 Rundata {
27 input: input.into().into(),
28 output: output.into().into(),
29 randoms: randoms.into().into(),
30 lists: lists.into().into(),
31 variables: variables.into().into(),
32 }
33 }
34}
35
36impl SelectableSource for Rundata {
37 async fn request<'a>(
38 &'a self,
39 selector: &crate::spec::Selector,
40 allowed_features: Features,
41 ) -> Result<Cow<'a, crate::spec::RuntimeAny>, crate::spec::FatalError> {
42 Self::enforce_required(Features::READ_RUNDATA, allowed_features)?;
43
44 Ok(Cow::Borrowed(match selector {
45 Selector::Coremap(mapping) => match mapping {
46 Coremapping::Input => &self.input,
47 Coremapping::Variables => &self.variables,
48 Coremapping::Randoms => &self.randoms,
49 Coremapping::Output => &self.output,
50 Coremapping::Lists => &self.lists,
51 Coremapping::Flags | Coremapping::Param => {
52 Self::mark_fallback_need(selector.clone())?
53 }
54 },
55 Selector::CoremapItem { .. } => Self::mark_fallback_need(selector.clone())?,
56 }))
57 }
58}