Skip to main content

tilo_actions/
prefill.rs

1//! Offering a parameter's current value: what the action's own state knows
2//! it would act with, which a surface fills and a caller may change.
3
4use crate::{ActionSpec, ActionType};
5
6impl ActionType {
7    /// Offer `value` in the field of the parameter `name`: its schema's
8    /// default, which a surface fills and a caller may change. A parameter
9    /// the action does not take is left as it is.
10    pub fn prefilled(&mut self, name: &str, value: serde_json::Value) {
11        if let Some(param) = self
12            .params
13            .iter_mut()
14            .find(|param| param.name.as_ref() == name)
15        {
16            *param = param.clone().with_default(value);
17        }
18    }
19}
20
21impl ActionSpec {
22    /// [`ActionType::prefilled`] on the action this spec publishes: this
23    /// item's, copied first when other items share the type.
24    pub fn prefilled(&mut self, name: &str, value: serde_json::Value) {
25        self.type_mut().prefilled(name, value);
26    }
27}