According the docs, NoError is a type that can never be instantiated. But when I looked at the code, it's a struct with a "dummy field" rather than an actual uninhabited type. The benefit of using an uninhabited type is that it makes it literally impossible to instantiate, which the compiler can then exploit to generate better optimised code.
So, is there any reason NoError isn't defined as an uninhabited type? It's pretty simple to do, just use an enum with no variants:
#[derive(Debug)]
pub enum NoError {}
According the docs,
NoErroris a type that can never be instantiated. But when I looked at the code, it's a struct with a "dummy field" rather than an actual uninhabited type. The benefit of using an uninhabited type is that it makes it literally impossible to instantiate, which the compiler can then exploit to generate better optimised code.So, is there any reason
NoErrorisn't defined as an uninhabited type? It's pretty simple to do, just use an enum with no variants: