#rust
@w Huh, I've never thought of that. That's a very interesting idea!
My guess would be that there may be some technical difficulties for implementing this. But maybe that'd be worth exploring
@diondokter @w I think we can do this today in user land by writing tests that take generic arguments constrained to the trait as input.
In languages like Haskell and PureScript, type classes (similar to traits in Rust) often have laws or properties that should hold, so it’s clear what the tests should cover.
For example: https://github.com/purescript-contrib/purescript-quickcheck-laws
I was so used to this idea that I went looking for the equivalent for Read/Write/Seek a while back: https://users.rust-lang.org/t/existing-tests-for-read-write-and-seek-traits/72991?u=paulyoung
@paulyoung @w how I imagine this would work is that you'd write an associated test. Then on a cargo test, it would find all types that implement the trait (even ones you the trait creator don't know about) and pass that through the test.
One thing though would be that you'd need a way to initialize every type in some way...
@diondokter @w with QuickCheck in Haskell/PureScript you typically define an instance of the Arbitrary type class (implement the trait in Rust)
A basic version could perhaps require types to implement Default or similar.
@diondokter @paulyoung @w Using a combination of generic tests and macros to generate them, you could make it very convenient to work with, but you’d still have to enumerate all the types you want to test.
This is really because logic for unknown types can have unanticipated effects, because arbitrary logic can fit in the type implementation (think, connecting to a database). Also if you’re searching for 1st party and 3rd party implementers, you can’t precisely (or even roughly) estimate the amount of computational work your tests will do.
@johnbchron @paulyoung @w it really depends on who runs the tests. Should it be run on crates.io? No
Run by the writer of the trait against everything that's out there? No
I think it should be run by users of the trait. When you import a trait, then it will run the tests against all it's impls in your project (and your dependencies maybe?)