Skip to content

Remove getopts_state from Env and add AnySet instead #443

Closed
@magicant

Description

@magicant

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeThis enhancement is backward-incompatible

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions