Skip to content

Commit

Permalink
Add ts-rs cargo feature to derive ts-rs (#708)
Browse files Browse the repository at this point in the history
* Add ts-rs cargo feature to derive ts-rs

* Add derive PartialEq for all modeling commands

* Fix empty variant structs to have a field to work with ts-rs
  • Loading branch information
jtran authored Jan 6, 2025
1 parent 7d3f93e commit 766bb5e
Show file tree
Hide file tree
Showing 21 changed files with 605 additions and 143 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion modeling-cmds-macros-impl/src/modeling_cmd_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ pub fn generate(input: ItemMod) -> TokenStream {
/// Definition of each modeling command.
#input
/// Commands that the KittyCAD engine can execute.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "derive-jsonschema-on-enums", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case", tag = "type")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum ModelingCmd {#(
#[doc = #docs]
Expand Down
6 changes: 6 additions & 0 deletions modeling-cmds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ serde_bytes = "0.11.15"
serde_json = { version = "1.0.134", optional = true }
slog = { version = "2.7.0", optional = true }
tabled = { version = "0.17", optional = true }
ts-rs = { version = "10.1.0", optional = true, features = [
"uuid-impl",
"no-serde-warnings",
"serde-json-impl",
] }
uuid = { version = "1.11.0", features = ["serde", "v4", "js"] }
webrtc = { version = "0.11", optional = true }

Expand All @@ -46,6 +51,7 @@ workspace = true
default = []
derive-jsonschema-on-enums = []
tabled = ["dep:tabled"]
ts-rs = ["dep:ts-rs"]
slog = ["dep:slog"]
cxx = ["dep:cxx"]
convert_client_crate = ["dep:kittycad"]
Expand Down
8 changes: 8 additions & 0 deletions modeling-cmds/src/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[serde(rename_all = "snake_case")]
#[display(style = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub enum Axis {
/// 'Y' axis.
Y = 1,
Expand All @@ -21,6 +23,8 @@ pub enum Axis {
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[serde(rename_all = "snake_case")]
#[display(style = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub enum Direction {
/// Increasing numbers.
Positive = 1,
Expand All @@ -42,6 +46,8 @@ impl std::ops::Mul for Direction {
/// An [`Axis`] paired with a [`Direction`].
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("({axis}, {direction})")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct AxisDirectionPair {
/// Axis specifier.
pub axis: Axis,
Expand All @@ -59,6 +65,8 @@ pub struct AxisDirectionPair {
/// [cglearn.eu](https://cglearn.eu/pub/computer-graphics/introduction-to-geometry#material-coordinate-systems-1)
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
#[display("forward: {forward}, up: {up}")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct System {
/// Axis the front face of a model looks along.
pub forward: AxisDirectionPair,
Expand Down
Loading

0 comments on commit 766bb5e

Please sign in to comment.