refinement
refinement copied to clipboard
Convenient creation of type-safe refinement types.
The implementation of the method `Refinement.to_inner()` has two problems: 1. It implicitly performs a (potentially expensive) `self.clone()`, and 2. It provides a clone of the stored value. Currently, the documentation...
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...
You can modify the inner value using `DerefMut`, even to something the predicate wouldn't allow. Example: ``` let two: Refinement = Refinement::new(2); *two.deref_mut() = 11; println!("{two}"); // prints `11` ```
Add an `apply` function that applies a function `f` to the underlying value of the Refinement type and then tries to refine the resulting value as well. Basically, this implements...