tilo_actions/resource/choices.rs
1//! Narrowing a declared action's parameter choices to what this instance
2//! offers: the sessions a greeter can start now, the challenge waiting for an
3//! answer.
4
5use super::ActionSpec;
6
7impl ActionSpec {
8 /// This action with `name`'s accepted values narrowed to `choices`: the
9 /// sessions a greeter offers now, the challenge waiting for an answer. Its
10 /// other parameters, operation and contract stay as declared, and an
11 /// unknown name leaves it as it is.
12 #[must_use]
13 pub fn with_param_choices(
14 mut self,
15 name: &str,
16 choices: impl IntoIterator<Item = std::borrow::Cow<'static, str>>,
17 ) -> Self {
18 let choices: Vec<std::borrow::Cow<'static, str>> = choices.into_iter().collect();
19 if let Some(param) = self
20 .type_mut()
21 .params
22 .iter_mut()
23 .find(|param| param.name == name)
24 {
25 param.choices = choices;
26 }
27 self
28 }
29}