For the enum case, this could be covered by refined types / pattern types:
- Implement minimal, internal-only pattern types in the type system by oli-obk · Pull Request #120131 · rust-lang/rust · GitHub
- Thoughts on pattern types and subtyping - #35
With your example, EncodingError
would be pattern_type!(Error is Error::A(_) | Error::E)
.