diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3a43fdb7..c1a0fd34 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,6 +4,6 @@ - In `def_enum.rs` add a new variant of `ModelingCmd` with your type, e.g. `MyNewCommand(MyNewCommand)`. - If your command responds with data: - In `output.rs`, add a `struct MyNewCommand` following the existing examples. - - Then scroll to the end of the file and `impl<'de> ModelingCmdOutput<'de> for MyNewCommand {}` + - Then scroll to the end of the file and `impl ModelingCmdOutput for MyNewCommand {}` - In `ok_response.rs` add your new type to the `build_enum!` macro. - - In `impl_traits.rs` follow the examples to implement `ModelingCmdVariant<'de>` for your type `MyNewCommand` using either the `impl_variant_output!` or the `impl_variant_empty!` macro. If your command responds with data, use the former. If your command has no response, use the latter. \ No newline at end of file + - In `impl_traits.rs` follow the examples to implement `ModelingCmdVariant` for your type `MyNewCommand` using either the `impl_variant_output!` or the `impl_variant_empty!` macro. If your command responds with data, use the former. If your command has no response, use the latter. \ No newline at end of file diff --git a/modeling-cmds/src/impl_traits.rs b/modeling-cmds/src/impl_traits.rs index 3ee80eea..be6f2660 100644 --- a/modeling-cmds/src/impl_traits.rs +++ b/modeling-cmds/src/impl_traits.rs @@ -2,7 +2,7 @@ use crate::{each_cmd::*, output as out, ModelingCmd, ModelingCmdVariant}; macro_rules! impl_variant_output { ($struct:ident) => { - impl<'de> ModelingCmdVariant<'de> for $struct { + impl ModelingCmdVariant for $struct { type Output = out::$struct; fn into_enum(self) -> ModelingCmd { ModelingCmd::$struct(self) @@ -16,7 +16,7 @@ macro_rules! impl_variant_output { macro_rules! impl_variant_empty { ($struct:ident) => { - impl<'de> ModelingCmdVariant<'de> for $struct { + impl ModelingCmdVariant for $struct { type Output = (); fn into_enum(self) -> ModelingCmd { ModelingCmd::$struct(self) diff --git a/modeling-cmds/src/output.rs b/modeling-cmds/src/output.rs index 185b9562..78f46216 100644 --- a/modeling-cmds/src/output.rs +++ b/modeling-cmds/src/output.rs @@ -256,35 +256,35 @@ pub struct EntityGetDistance { pub max_distance: f64, } -impl<'de> ModelingCmdOutput<'de> for Export {} -impl<'de> ModelingCmdOutput<'de> for SelectWithPoint {} -impl<'de> ModelingCmdOutput<'de> for HighlightSetEntity {} -impl<'de> ModelingCmdOutput<'de> for EntityGetChildUuid {} -impl<'de> ModelingCmdOutput<'de> for EntityGetNumChildren {} -impl<'de> ModelingCmdOutput<'de> for EntityGetParentId {} -impl<'de> ModelingCmdOutput<'de> for EntityGetAllChildUuids {} -impl<'de> ModelingCmdOutput<'de> for EntityGetDistance {} -impl<'de> ModelingCmdOutput<'de> for SelectGet {} -impl<'de> ModelingCmdOutput<'de> for GetEntityType {} -impl<'de> ModelingCmdOutput<'de> for Solid3dGetAllEdgeFaces {} -impl<'de> ModelingCmdOutput<'de> for Solid3dGetAllOppositeEdges {} -impl<'de> ModelingCmdOutput<'de> for Solid3dGetOppositeEdge {} -impl<'de> ModelingCmdOutput<'de> for Solid3dGetPrevAdjacentEdge {} -impl<'de> ModelingCmdOutput<'de> for Solid3dGetNextAdjacentEdge {} -impl<'de> ModelingCmdOutput<'de> for MouseClick {} -impl<'de> ModelingCmdOutput<'de> for CurveGetType {} -impl<'de> ModelingCmdOutput<'de> for CurveGetControlPoints {} -impl<'de> ModelingCmdOutput<'de> for TakeSnapshot {} -impl<'de> ModelingCmdOutput<'de> for PathGetInfo {} -impl<'de> ModelingCmdOutput<'de> for PathGetCurveUuidsForVertices {} -impl<'de> ModelingCmdOutput<'de> for PathGetVertexUuids {} -impl<'de> ModelingCmdOutput<'de> for PlaneIntersectAndProject {} -impl<'de> ModelingCmdOutput<'de> for CurveGetEndPoints {} -impl<'de> ModelingCmdOutput<'de> for ImportFiles {} -impl<'de> ModelingCmdOutput<'de> for Mass {} -impl<'de> ModelingCmdOutput<'de> for Volume {} -impl<'de> ModelingCmdOutput<'de> for Density {} -impl<'de> ModelingCmdOutput<'de> for SurfaceArea {} -impl<'de> ModelingCmdOutput<'de> for CenterOfMass {} -impl<'de> ModelingCmdOutput<'de> for GetSketchModePlane {} -impl<'de> ModelingCmdOutput<'de> for () {} +impl ModelingCmdOutput for Export {} +impl ModelingCmdOutput for SelectWithPoint {} +impl ModelingCmdOutput for HighlightSetEntity {} +impl ModelingCmdOutput for EntityGetChildUuid {} +impl ModelingCmdOutput for EntityGetNumChildren {} +impl ModelingCmdOutput for EntityGetParentId {} +impl ModelingCmdOutput for EntityGetAllChildUuids {} +impl ModelingCmdOutput for EntityGetDistance {} +impl ModelingCmdOutput for SelectGet {} +impl ModelingCmdOutput for GetEntityType {} +impl ModelingCmdOutput for Solid3dGetAllEdgeFaces {} +impl ModelingCmdOutput for Solid3dGetAllOppositeEdges {} +impl ModelingCmdOutput for Solid3dGetOppositeEdge {} +impl ModelingCmdOutput for Solid3dGetPrevAdjacentEdge {} +impl ModelingCmdOutput for Solid3dGetNextAdjacentEdge {} +impl ModelingCmdOutput for MouseClick {} +impl ModelingCmdOutput for CurveGetType {} +impl ModelingCmdOutput for CurveGetControlPoints {} +impl ModelingCmdOutput for TakeSnapshot {} +impl ModelingCmdOutput for PathGetInfo {} +impl ModelingCmdOutput for PathGetCurveUuidsForVertices {} +impl ModelingCmdOutput for PathGetVertexUuids {} +impl ModelingCmdOutput for PlaneIntersectAndProject {} +impl ModelingCmdOutput for CurveGetEndPoints {} +impl ModelingCmdOutput for ImportFiles {} +impl ModelingCmdOutput for Mass {} +impl ModelingCmdOutput for Volume {} +impl ModelingCmdOutput for Density {} +impl ModelingCmdOutput for SurfaceArea {} +impl ModelingCmdOutput for CenterOfMass {} +impl ModelingCmdOutput for GetSketchModePlane {} +impl ModelingCmdOutput for () {} diff --git a/modeling-cmds/src/traits.rs b/modeling-cmds/src/traits.rs index 6c114dae..5651daee 100644 --- a/modeling-cmds/src/traits.rs +++ b/modeling-cmds/src/traits.rs @@ -1,11 +1,12 @@ -use serde::Serialize; +use schemars::JsonSchema; +use serde::{de::DeserializeOwned, Serialize}; use crate::ModelingCmd; /// Some modeling command executed on the KittyCAD engine. -pub trait ModelingCmdVariant<'de>: Serialize { +pub trait ModelingCmdVariant: Serialize { /// What the command responds with - type Output: ModelingCmdOutput<'de>; + type Output: ModelingCmdOutput; /// Take this specific enum variant, and create the general enum. fn into_enum(self) -> ModelingCmd; /// The command's name. @@ -13,11 +14,11 @@ pub trait ModelingCmdVariant<'de>: Serialize { } /// Anything that can be a ModelingCmd output. -pub trait ModelingCmdOutput<'de>: std::fmt::Debug + Serialize + serde::Deserialize<'de> + schemars::JsonSchema {} +pub trait ModelingCmdOutput: std::fmt::Debug + Serialize + DeserializeOwned + JsonSchema {} -impl<'de, CmdVariant> From for ModelingCmd +impl From for ModelingCmd where - CmdVariant: ModelingCmdVariant<'de>, + CmdVariant: ModelingCmdVariant, { fn from(value: CmdVariant) -> Self { value.into_enum() diff --git a/modeling-session/src/lib.rs b/modeling-session/src/lib.rs index ede0af91..321f452a 100644 --- a/modeling-session/src/lib.rs +++ b/modeling-session/src/lib.rs @@ -82,7 +82,7 @@ impl Session { cmd: Cmd, ) -> Result where - Cmd: kittycad_modeling_cmds::ModelingCmdVariant<'de>, + Cmd: kittycad_modeling_cmds::ModelingCmdVariant, { // All messages to the KittyCAD Modeling API will be sent over the WebSocket as Text. // The text will contain JSON representing a `ModelingCmdReq`.