9 ms·
In Rust, wouldn't implementing BitOr for Fn/FnOnce/FnMut violate the orphan rule?
by tyushk 7mo ago
In Rust, wouldn't implementing BitOr for Fn/FnOnce/FnMut violate the orphan rule?
- wavemode 7mo agoI'm envisioning that in Rust (and Python), the operator overload would be on a class/struct. It would be the macro/decorator (the same one that adds logging) which would turn the function definition into an object that implements Fn.
- carterschonwald 7mo agosomehow this counts like model cot.
- graemep 7mo agoI have done exactly that as an exercise in what you can do with Python: overload |, and a decorator that you can use to on any function to return an instance of a callable class that calls that function and overloads |. Whether it is a good idea to use it is another matter (it does not feel Pythonic), but it is easy to implement.