Types for Parsing Invariants
High level description
ANISE currently contains instances where unreachable panics occur within match statements, as well as cases where malformed structs may cause panics during type conversions. To improve safety and robustness, this issue proposes introducing new struct and enum types that enforce invariants at the type level, preventing invalid states from being representable.
By encoding constraints directly in the type system, we can eliminate unreachable panics and reduce the risk of runtime failures due to malformed data.
Requirements
- Prevent parsing from creating structs with invalid internal state
- Replace unstructured types with domain-specific types
Test plans
- Include regression tests that reproduce original error
- Ensure that regression tests pass following implementation
Design
- Replace match arms with unreachable statements with exhausting enums
- Use the newtype pattern to prevent invalid data from being constructed
- Use
TryFromto gracefully handle fallible conversions - Where necessary, annotate enums as
non_exhaustiveto prevent introducing breaking changes
Thanks for creating all of these issues Johnathan, I think they're spot-on. One thing to keep in mind is the Python interface, which doesn't support the same level of generics as the Rust code. Let me know if the documentation needs clarifications on how to set up the Rust or Python development environments.