I am having a datatype whose construction might fail.
Some of the time this datatype is constructed with user-provided values. However, many other times they are created based on static information (i.e. 'hard-coded'). In those cases, we could not only do the construction at compile-time, but also tell at compile-time whether the construction would succeed or fail, transforming run-time errors into compile-time errors.
An example would be to create an URI-datatype from a string. Since there are many strings that indicate invalid URIs, this might fail. Finding out about this failure at compile-time would be very useful.
Currently, when these kind of 'hard-coded' datatypes are constructed, it is common to immediately call
expect(error_message) on them. This will of course happily fail with a panic at runtime when the construction failed.
Is there a version of
expect that would be called at compile-time (and 'panic' at compile-time if a non-success was encountered)?
Or is there another way to do this?