Open T0mstone opened 1 year ago
Hmm good point. Would a immutable model be more appropriate? Or maybe something like map(self, func) -> Optional<Refinement>
? Applies func to self and returns a refinement value of the result else None if it doesn't satisfy the condition?
Yes, immutable would definitely be the way to go, since once the user has the power to mutate the inner value, all guarantees are off.
The map function also sounds nice, even though you can already do it with Refinement::new(func(self.into_inner()))
, but not having to type all that every time would certainly be nice.
You can modify the inner value using
DerefMut
, even to something the predicate wouldn't allow.Example: