2bdkid / refinement

Convenient creation of type-safe refinement types.
18 stars 4 forks source link

Add a constructor `Refinement::try_new` #7

Open 8573 opened 1 year ago

8573 commented 1 year ago

Add a constructor Refinement::try_new that returns the original input value if it does not satisfy the predicate, rather than discarding the input value in that case as does Refinement::new.

This could be useful if the input value is expensive or impossible to reconstruct and is wanted even if it does not satisfy the predicate (for example, to report an error).

I believe this change raises the library's minimum supported Rust version (MSRV) from 1.31 to 1.34. Rust 1.34 is supported by distributions including Debian oldoldstable.