Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom TypedShape to reference dyn Shape instead #216

Merged
merged 6 commits into from
Jul 15, 2024

Conversation

Neo-Zhixing
Copy link
Contributor

@Neo-Zhixing Neo-Zhixing commented Jul 2, 2024

The existing TypedShape::Custom contains a user-defined shape with a type identified by a number.

This number has questionable utility. Let's make it so that TypedShape references the custom shape with a &dyn Shape instead. The user may check for the actual custom shape type using downcast.

Please let me know if there are any reasons to keep this as a u32 I might not be aware of.

/// A custom user-defined shape with a type identified by a number.
Custom(u32),
/// A custom user-defined shape.
Custom(&'a dyn Shape),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a dyn Shape serialize/deserialize ?

Copy link
Member

@sebcrozet sebcrozet Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vrixyz This would be difficult due to the Deserialize trait bound having a lifetime. This is generally worked around using erased_serde but some additional steps are needed to make deserialization actually work. This sounds out of the scope of this PR.

DeserializableWorkspaceData::Custom(_) => None,
DeserializableWorkspaceData::Custom => None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand that custom shapes are (currently) not supported by serialization/deserialization ? (at least here specifically)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. And this is the same behavior as before.

@Vrixyz Vrixyz requested a review from sebcrozet July 5, 2024 14:45
Copy link
Member

@sebcrozet sebcrozet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! The u32 was supposed to be a unique id identifying the custom shape type so that some custom serialization/deserialization code could handle it. Though that custom ser/deser isn’t implemented yet and will probably not be implemented for some time.
So I think it’s is fine to remove the u32 for now. Eventually, it will probably be re-added but as a Uuid instead.

@Vrixyz Vrixyz merged commit 2ba291c into dimforge:master Jul 15, 2024
5 checks passed
@Neo-Zhixing Neo-Zhixing deleted the custom-typed-shape branch July 20, 2024 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants