plux_rs/function/
request.rs

1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4
5use crate::variable::VariableType;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Request {
9    pub name: String,
10    pub inputs: Vec<VariableType>,
11    pub output: Option<VariableType>,
12}
13
14impl Request {
15    pub fn new<S: Into<String>>(
16        name: S,
17        inputs: Vec<VariableType>,
18        output: Option<VariableType>,
19    ) -> Self {
20        Self {
21            name: name.into(),
22            inputs,
23            output,
24        }
25    }
26}
27
28impl Display for Request {
29    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30        write!(
31            f,
32            "{}({}) -> {}",
33            self.name,
34            self.inputs
35                .iter()
36                .map(|x| format!("{x}"))
37                .collect::<Vec<_>>()
38                .join(", "),
39            match self.output {
40                Some(x) => format!("{x}"),
41                None => "void".to_string(),
42            }
43        )
44    }
45}