1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use schemars::JsonSchema;
use serde::{de::DeserializeOwned, Serialize};

use crate::ModelingCmd;

/// Some modeling command executed on the KittyCAD engine.
pub trait ModelingCmdVariant: Serialize {
    /// What the command responds with
    type Output: ModelingCmdOutput;
    /// Take this specific enum variant, and create the general enum.
    fn into_enum(self) -> ModelingCmd;
    /// The command's name.
    fn name() -> &'static str;
}

/// Anything that can be a ModelingCmd output.
pub trait ModelingCmdOutput: std::fmt::Debug + Serialize + DeserializeOwned + JsonSchema {}

impl<CmdVariant> From<CmdVariant> for ModelingCmd
where
    CmdVariant: ModelingCmdVariant,
{
    fn from(value: CmdVariant) -> Self {
        value.into_enum()
    }
}