diff --git a/execution-plan/src/primitive.rs b/execution-plan/src/primitive.rs index e3f3882d..fcd7ebf5 100644 --- a/execution-plan/src/primitive.rs +++ b/execution-plan/src/primitive.rs @@ -1,4 +1,4 @@ -use kittycad_modeling_cmds::shared::Angle; +use kittycad_modeling_cmds::{base64::Base64Data, shared::Angle}; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -58,6 +58,12 @@ impl From> for Primitive { } } +impl From for Primitive { + fn from(value: Base64Data) -> Self { + Self::Bytes(value.into()) + } +} + impl TryFrom for String { type Error = ExecutionError; @@ -142,6 +148,14 @@ impl TryFrom for Vec { } } +impl TryFrom for Base64Data { + type Error = ExecutionError; + + fn try_from(value: Primitive) -> Result { + Vec::::try_from(value).map(Base64Data::from) + } +} + impl TryFrom for bool { type Error = ExecutionError; diff --git a/execution-plan/src/value/impls.rs b/execution-plan/src/value/impls.rs index 46124872..00afe7aa 100644 --- a/execution-plan/src/value/impls.rs +++ b/execution-plan/src/value/impls.rs @@ -5,9 +5,10 @@ //! - This canonical ordering is the order of the struct's fields in its Rust source code definition. //! - Enums get laid out by first putting the variant as a string, then putting the variant's fields. use kittycad_modeling_cmds::{ + base64::Base64Data, ok_response::OkModelingCmdResponse, output, - shared::{Angle, PathSegment, Point2d, Point3d}, + shared::{Angle, PathSegment, Point2d, Point3d, Point4d}, }; use uuid::Uuid; @@ -26,6 +27,9 @@ fn err() -> ExecutionError { ExecutionError::MemoryWrongSize } +/// Macro to generate an `impl Value` for the given type `$subject`. +/// The type `$subject` must be "primitive-ish", +/// i.e. something that can be converted Into a Primitive and TryFrom a primitive macro_rules! impl_value_on_primitive_ish { ($subject:ident) => { impl Value for $subject { @@ -52,6 +56,7 @@ type VecU8 = Vec; impl_value_on_primitive_ish!(VecU8); impl_value_on_primitive_ish!(Angle); impl_value_on_primitive_ish!(usize); +impl_value_on_primitive_ish!(Base64Data); /// Macro to generate the methods of trait `Value` for the given fields. /// Args: @@ -100,10 +105,22 @@ where impl_value_on_struct_fields!(x, y, z); } +impl Value for Point4d +where + Primitive: From, + T: Value, +{ + impl_value_on_struct_fields!(x, y, z, w); +} + impl Value for kittycad_modeling_cmds::shared::Color { impl_value_on_struct_fields!(r, g, b, a); } +impl Value for kittycad_modeling_cmds::shared::ExportFile { + impl_value_on_struct_fields!(name, contents); +} + /// Layout: /// - One memory address to store the variant name /// - Following memory addresses to store the variant's single field.