isn't the problem that rw is still r, so passes checks for both?
can't you make one rw and the other r(-w)?
On the surface, this addition doesn't seem significant. However, it opens up a world of possibilities for enabling powerful design patterns that are based on trait implementations that are named, generic, and overlappable. One of the greatest strengths of CGP is to enable safe, zero-cost, compile-time dispatching through the trait system to accomplish the things that in OOP would typically require dynamic dispatch with runtime errors.
Just a FYI from their main page:
As of 2025, CGP remains in its early stages of development. While promising, it still has several rough edges, particularly in areas such as documentation, tooling, debugging techniques, community support, and ecosystem maturity.
...
At this stage, CGP is best suited for early adopters and potential contributors who are willing to experiment and help shape its future.
The issue is really that `specialization` *has* to deal with lifetimes, even when there is apparently none. The example core with `Read` and `Read + Seek` also suffers from lifetime issues: some type could implement `Seek` depending on some lifetime and this would make your specialization unsound. For this reason `min_specialization` does not accept your specialization.
hackyhacky•4h ago
In this use case, my instinct tells me that trait specialization is the wrong tool for the job. The author is trying to dispatch different functions based on a flag set in the caller. I can think of two more elegant ways to do this:
* Make the file system itself a trait, with implementations for read-only and read/write. Pass the concrete implementation as a parameter to the function using it.
* Store the capabilities as a variable in the file system object and query it at runtime. This can be done with an if.
Sometimes the simpler approach is better.
nesarkvechnep•3h ago
dwattttt•2h ago
> Make the file system itself a trait, with implementations for read-only and read/write
Those are separate concrete implementations between read-only and read-write; a write operation can be implemented on the read-write implementation only.
nesarkvechnep•1h ago
dwattttt•1h ago