1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use serde::Serialize;

use crate::ModelingCmd;

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

/// Anything that can be a ModelingCmd output.
pub trait ModelingCmdOutput<'de>: std::fmt::Debug + Serialize + serde::Deserialize<'de> + schemars::JsonSchema {}

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