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.
The
GetoptsStatestruct is declared in theyash-envcrate while it is only used in thegetoptsbuilt-in which is implemented in theyash-builtincrate. For better cohesion, the state should be declared in theyash-builtincrate.To allow saving the state in the environment from the built-in,
Envwill need to contain something likeHashSet<Box<dyn Any>>that differentiates entries by their type ids. With such a set, any users ofEnvcan add arbitrary data that have the same lifetime asEnvand 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 haveThe data inBox<dyn AnyDebug>instead ofBox<dyn Any>wheretrait AnyDebug: Any + Debug {}.Envhave to be cloneable, so we will need a custom trait anyway.