kittycad_modeling_cmds/
traits.rs

1use schemars::JsonSchema;
2use serde::{de::DeserializeOwned, Serialize};
3
4use crate::ModelingCmd;
5
6/// Some modeling command executed on the KittyCAD engine.
7pub trait ModelingCmdVariant: Serialize {
8    /// What the command responds with
9    type Output: ModelingCmdOutput;
10    /// Take this specific enum variant, and create the general enum.
11    fn into_enum(self) -> ModelingCmd;
12    /// The command's name.
13    fn name() -> &'static str;
14}
15
16/// Anything that can be a ModelingCmd output.
17pub trait ModelingCmdOutput: std::fmt::Debug + Serialize + DeserializeOwned + JsonSchema {}
18
19impl<CmdVariant> From<CmdVariant> for ModelingCmd
20where
21    CmdVariant: ModelingCmdVariant,
22{
23    fn from(value: CmdVariant) -> Self {
24        value.into_enum()
25    }
26}