Error type for function that can not fail

FromStr returns a Result<Self, Self::Error>. Assuming a conversion will always return an enum, and one of the enum's variant is a defined Invalid value. What's the proper way to signal that the Result's E case can never happen? Using the return type Result<Self, ()> would, at least to me, signal that there is a possible error, but that it is both unique and obvious.

Is there something along the line of Result<MyEnum, WillNeverHappen>?

Infallible is the standard type for representing operations that can't fail.

Eventually the never type ! will probably take over for that, but it's still unstable.

6 Likes