tilo_actions/resource/carried.rs
1//! What a carrier action names to one caller: only the actions their own call of it is not
2//! refused for.
3
4use std::sync::Arc;
5
6use super::ActionSpec;
7
8impl ActionSpec {
9 /// Take the actions `refused` names out of what this action says it carries
10 /// ([`Self::carrying`]): out of the ids the schemas of its parameters name. Whoever
11 /// lists a resource to a caller calls it with the actions it drops for them, or lists
12 /// to them as not allowed, so a carrier names to that caller only what their own call
13 /// of it is not refused for. An action that carries none, or names none of them, stays
14 /// as it is and keeps the schema it shares.
15 pub fn without_carried(&mut self, refused: &[&str]) {
16 if !self.carrier {
17 return;
18 }
19 let cut: Vec<(usize, serde_json::Value)> = self
20 .params
21 .iter()
22 .enumerate()
23 .filter_map(|(at, param)| {
24 let schema = param.schema.as_deref()?;
25 Some((at, crate::params::without_named(schema, refused)?))
26 })
27 .collect();
28 if cut.is_empty() {
29 return;
30 }
31 let params = &mut self.type_mut().params;
32 for (at, schema) in cut {
33 if let Some(param) = params.get_mut(at) {
34 param.schema = Some(Arc::new(schema));
35 }
36 }
37 }
38}