Compare commits

..

1 Commits

Author SHA1 Message Date
c9e27ffb95 WIP 2023-12-04 12:16:50 -06:00
2 changed files with 7 additions and 7 deletions

View File

@ -12,9 +12,8 @@ pub trait Composite<const SIZE: usize>: Sized {
impl Composite<3> for kittycad::types::Point3D {
fn into_parts(self) -> [Value; 3] {
[self.x, self.y, self.z]
.map(NumericValue::Float)
.map(Value::NumericValue)
let points = [self.x, self.y, self.z];
points.map(NumericValue::Float).map(Value::NumericValue)
}
fn from_parts(values: [Value; 3]) -> Result<Self, ExecutionError> {

View File

@ -6,10 +6,9 @@
//! You can think of it as a domain-specific language for making KittyCAD API calls and using
//! the results to make other API calls.
use std::{collections::HashMap, fmt};
use composite::Composite;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt};
mod composite;
#[cfg(test)]
@ -271,6 +270,8 @@ pub enum ExecutionError {
CannotApplyOperation { op: Operation, operands: Vec<Value> },
#[error("Tried to read a '{expected}' from KCEP program memory, found an '{actual}' instead")]
MemoryWrongType { expected: &'static str, actual: String },
#[error("Wrong size of memory trying to read value from KCEP program memory: got {actual} but wanted {expected}")]
MemoryWrongSize { expected: usize, actual: usize },
}
/// Take an array of result and return a result of array.
@ -278,9 +279,9 @@ pub enum ExecutionError {
/// If any member of the array was Err(E), return Err with the first E value.
fn arr_res_to_res_array<T, E, const N: usize>(arr: [Result<T, E>; N]) -> Result<[T; N], E> {
let mut out = core::array::from_fn(|_| None);
for (i, res) in arr.into_iter().enumerate() {
for (i, res) in arr.enumerate() {
out[i] = match res {
Ok(x) => Some(x),
Ok(x) => x,
Err(e) => return Err(e),
};
}