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

Remove getopts_state from Env and add AnySet instead #443

Closed
magicant opened this issue Dec 31, 2024 · 1 comment · Fixed by #445
Closed

Remove getopts_state from Env and add AnySet instead #443

magicant opened this issue Dec 31, 2024 · 1 comment · Fixed by #445
Labels
breaking change This enhancement is backward-incompatible

Comments

@magicant
Copy link
Owner

magicant commented Dec 31, 2024

The GetoptsState struct is declared in the yash-env crate while it is only used in the getopts built-in which is implemented in the yash-builtin crate. For better cohesion, the state should be declared in the yash-builtin crate.

To allow saving the state in the environment from the built-in, Env will need to contain something like HashSet<Box<dyn Any>> that differentiates entries by their type ids. With such a set, any users of Env can add arbitrary data that have the same lifetime as Env and that can only be accessed from contexts that know the data's type.

We might want to wait for dyn upcasting coercion to stabilize so that we can have Box<dyn AnyDebug> instead of Box<dyn Any> where trait AnyDebug: Any + Debug {}. The data in Env have to be cloneable, so we will need a custom trait anyway.

@magicant magicant added this to yash-rs Dec 30, 2024
@magicant magicant converted this from a draft issue Dec 31, 2024
@magicant magicant added the breaking change This enhancement is backward-incompatible label Dec 31, 2024
@magicant magicant moved this from To do to In progress in yash-rs Jan 13, 2025
@magicant
Copy link
Owner Author

Since we want to mutably borrow the data from the env, we need to use a map rather than a set to hold any data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change This enhancement is backward-incompatible
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant