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

PhantomData in structs to prevent outside instantiation #172

Merged
merged 4 commits into from
Dec 9, 2024

Conversation

michael-okeefe
Copy link
Collaborator

Addresses:
https://github.nrel.gov/MBAP/fastsim/issues/362

Note: I ended up using the #[non_exhaustive] meta word syntax as it does prevent Struct Instantiation outside of the crate (e.g., I tested from fastsim-cli and the compiler would not let me struct instantiate).

Michael O'Keefe added 4 commits November 15, 2024 12:34
This prevents code outside of the crate from
constructing the given structs using a StructExpression
(i.e., MyStruct { ... }). I have tested and confirmed
that, for example, I cannot instatiate a struct from
the fastsim-cli crate. This was deemed to be a little
less convoluted than using a PhantomData typed method
which essentially does the same thing.
@michael-okeefe michael-okeefe self-assigned this Dec 6, 2024
@michael-okeefe michael-okeefe marked this pull request as ready for review December 6, 2024 19:58
Copy link
Collaborator

@calbaker calbaker left a comment

Choose a reason for hiding this comment

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

Note: I ended up using the #[non_exhaustive] meta word syntax as it does prevent Struct Instantiation outside of the crate (e.g., I tested from fastsim-cli and the compiler would not let me struct instantiate).

@michael-okeefe I came here to ask this very question and you preempted me! Nice work!

@calbaker calbaker merged commit 9398e39 into fastsim-3 Dec 9, 2024
9 checks passed
@calbaker calbaker deleted the f3/use-phantomdata branch December 9, 2024 15:38
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.

2 participants