Skip to main content

combs_mesh/blocks/
function.rs

1//! `fnc` — callable function definitions carried by the emoji.
2
3use serde::{Deserialize, Serialize};
4
5/// Function definitions block.
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7pub struct FunctionBlock {
8    /// The functions.
9    #[serde(default)]
10    pub definitions: Vec<FunctionDef>,
11}
12
13/// A single function definition.
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15pub struct FunctionDef {
16    /// Function name.
17    pub name: String,
18    /// CRUD-ish kind (or a custom one).
19    pub kind: FunctionKind,
20    /// Parameter names.
21    #[serde(default)]
22    pub params: Vec<String>,
23    /// Implementation body (script/expression; interpreted by runtimes).
24    #[serde(default)]
25    pub body: String,
26}
27
28/// The kind of function.
29#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
30pub enum FunctionKind {
31    /// Creates something.
32    Add,
33    /// Reads something.
34    Get,
35    /// Mutates something.
36    Update,
37    /// Anything else.
38    Custom(String),
39}