Skip to content

Commit

Permalink
Fix empty variant structs to have a field to work with ts-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
jtran committed Jan 4, 2025
1 parent 53c501a commit 53661d4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 25 deletions.
99 changes: 77 additions & 22 deletions modeling-cmds/src/def_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ define_modeling_cmd_enum! {

/// Start a new path.
#[derive(
Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant,
Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant,

Check warning on line 61 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L61

Added line #L61 was not covered by tests
)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 63 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L63

Added line #L63 was not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct StartPath;
pub struct StartPath {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Move the path's "pen".
/// If you're in sketch mode, these coordinates are in the local coordinate system,
Expand Down Expand Up @@ -267,10 +272,15 @@ define_modeling_cmd_enum! {
}

/// Gets the default camera's camera settings
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 276 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L275-L276

Added lines #L275 - L276 were not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct DefaultCameraGetSettings;
pub struct DefaultCameraGetSettings {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Change what the default camera is looking at.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
Expand Down Expand Up @@ -549,10 +559,15 @@ define_modeling_cmd_enum! {
}

/// Removes all of the Objects in the scene
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 563 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L562-L563

Added lines #L562 - L563 were not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct SceneClearAll;
pub struct SceneClearAll {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Replaces current selection with these entities (by UUID).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
Expand Down Expand Up @@ -920,16 +935,26 @@ define_modeling_cmd_enum! {
/// Disable sketch mode.
/// If you are sketching on a face, be sure to not disable sketch mode until you have extruded.
/// Otherwise, your object will not be fused with the face.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 939 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L938-L939

Added lines #L938 - L939 were not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct SketchModeDisable;
pub struct SketchModeDisable {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Get the plane for sketch mode.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 950 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L949-L950

Added lines #L949 - L950 were not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct GetSketchModePlane;
pub struct GetSketchModePlane {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Get the plane for sketch mode.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
Expand Down Expand Up @@ -966,18 +991,28 @@ define_modeling_cmd_enum! {
/// Sets whether or not changes to the scene or its objects will be done as a "dry run"
/// In a dry run, successful commands won't actually change the model.
/// This is useful for catching errors before actually making the change.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 995 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L994-L995

Added lines #L994 - L995 were not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct EnableDryRun;
pub struct EnableDryRun {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Sets whether or not changes to the scene or its objects will be done as a "dry run"
/// In a dry run, successful commands won't actually change the model.
/// This is useful for catching errors before actually making the change.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 1008 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L1007-L1008

Added lines #L1007 - L1008 were not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct DisableDryRun;
pub struct DisableDryRun {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Set the background color of the scene.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant)]
Expand Down Expand Up @@ -1311,11 +1346,16 @@ define_modeling_cmd_enum! {

/// Use orthographic projection.
#[derive(
Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize, ModelingCmdVariant,
Clone, Debug, Default, PartialEq, Deserialize, JsonSchema, Serialize, ModelingCmdVariant,

Check warning on line 1349 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L1349

Added line #L1349 was not covered by tests
)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 1351 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L1351

Added line #L1351 was not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct DefaultCameraSetOrthographic;
pub struct DefaultCameraSetOrthographic {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Use perspective projection.
#[derive(
Expand Down Expand Up @@ -1399,24 +1439,39 @@ define_modeling_cmd_enum! {
}

/// Clear the selection
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize, ModelingCmdVariant)]
#[derive(Clone, Debug, Default, PartialEq, Deserialize, JsonSchema, Serialize, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 1443 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L1442-L1443

Added lines #L1442 - L1443 were not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct SelectClear;
pub struct SelectClear {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Find all IDs of selected entities
#[derive(Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize, ModelingCmdVariant)]
#[derive(Clone, Debug, Default, PartialEq, Deserialize, JsonSchema, Serialize, ModelingCmdVariant)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 1454 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L1453-L1454

Added lines #L1453 - L1454 were not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct SelectGet;
pub struct SelectGet {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Get the number of objects in the scene
#[derive(
Clone, Debug, PartialEq, Deserialize, JsonSchema, Serialize, ModelingCmdVariant,
Clone, Debug, Default, PartialEq, Deserialize, JsonSchema, Serialize, ModelingCmdVariant,

Check warning on line 1465 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L1465

Added line #L1465 was not covered by tests
)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]

Check warning on line 1467 in modeling-cmds/src/def_enum.rs

View check run for this annotation

Codecov / codecov/patch

modeling-cmds/src/def_enum.rs#L1467

Added line #L1467 was not covered by tests
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
pub struct GetNumObjects;
pub struct GetNumObjects {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
}

/// Make a new path by offsetting an object by a given distance.
/// The new path's ID will be the ID of this command.
Expand Down
1 change: 1 addition & 0 deletions modeling-cmds/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub enum DistanceType {
Euclidean {
#[cfg(feature = "ts-rs")]
/// Work around issue with ts-rs not allowing tag on an empty variant.
#[serde(default, skip)]
_fix_ts_rs: (),
},
/// The distance between objects along the specified axis
Expand Down
2 changes: 1 addition & 1 deletion modeling-session/examples/cube_png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn main() -> Result<()> {
let path_id = Uuid::new_v4();
let path = path_id.into();
session
.run_command(path, ModelingCmd::StartPath(StartPath {}))
.run_command(path, ModelingCmd::StartPath(StartPath::default()))
.await
.context("could not create path")?;

Expand Down
2 changes: 1 addition & 1 deletion modeling-session/examples/cube_png_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn main() -> Result<()> {
let path_id = Uuid::new_v4();
let path = path_id.into();
session
.run_command(path, StartPath {}.into())
.run_command(path, StartPath::default().into())
.await
.context("could not create path")?;

Expand Down
2 changes: 1 addition & 1 deletion modeling-session/examples/lsystem_png_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn main() -> Result<()> {
let path_id = Uuid::new_v4();
let path = path_id.into();
session
.run_command(path, ModelingCmd::from(StartPath {}))
.run_command(path, ModelingCmd::from(StartPath::default()))
.await
.context("could not create path")?;

Expand Down

0 comments on commit 53661d4

Please sign in to comment.