-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39b2cfd
commit df351ca
Showing
4 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
execution-plan-macros/src/snapshots/kittycad_execution_plan_macros__tests__enum.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
source: execution-plan-macros/src/lib.rs | ||
expression: formatted | ||
--- | ||
impl kittycad_execution_plan_traits::Value for FooEnum { | ||
fn into_parts(self) -> Vec<kittycad_execution_plan_traits::Primitive> { | ||
match self { | ||
FooEnum::A { x } => { | ||
vec![ | ||
Primitive::from(stringify!(A).to_owned()), | ||
Primitive::from(x), | ||
] | ||
} | ||
FooEnum::B { y } => { | ||
vec![ | ||
Primitive::from(stringify!(B).to_owned()), | ||
Primitive::from(y), | ||
] | ||
} | ||
FooEnum::C(field0, field1) => { | ||
vec![ | ||
Primitive::from(stringify!(C).to_owned()), | ||
Primitive::from(field0), | ||
Primitive::from(field1), | ||
] | ||
} | ||
} | ||
} | ||
|
||
fn from_parts<I>(values: &mut I) -> Result<Self, kittycad_execution_plan_traits::MemoryError> | ||
where | ||
I: Iterator<Item = Option<kittycad_execution_plan_traits::Primitive>>, | ||
{ | ||
let variant_name = String::from_parts(values)?; | ||
match variant_name.as_str() { | ||
stringify!(A) => { | ||
let x = usize::from_parts(values)?; | ||
Ok(Self::A { x }) | ||
} | ||
stringify!(B) => { | ||
let y = usize::from_parts(values)?; | ||
Ok(Self::B { y }) | ||
} | ||
stringify!(C) => { | ||
let field0 = usize::from_parts(values)?; | ||
let field1 = String::from_parts(values)?; | ||
Ok(Self::C(field0, field1)) | ||
} | ||
other => Err( | ||
kittycad_execution_plan_traits::MemoryError::InvalidEnumVariant { | ||
expected_type: stringify!(FooEnum).to_owned(), | ||
actual: other.to_owned(), | ||
}, | ||
), | ||
} | ||
} | ||
} | ||
|