Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> test the boundaries to fully understand at a fundamental level.

This sort of thing is why I wrote https://crates.io/crates/misfortunate

Rust lets me write safe implementations of well-known Traits like Ord (the trait which compares things because they are ordered) but promises the outcome when these traits are relied upon elsewhere is always safe even if my implementations are very silly.

So I can sort() things for which I've implemented nonsensical ordering (e.g. they all claim they're before each other) and Rust promises that's still safe. This futile task might well not finish and if it does finish they won't seem any more or less "sorted" than they were before I tried, but it won't crash or do anything unfathomable.

And indeed that's exactly what happens, cementing my faith in the idea of Rust.

[Not all Rust's traits are safe. If you have to say "unsafe" to write the implementation then it wasn't safe, and if you do something nonsensical in an unsafe trait then you get to keep both halves when it breaks, misfortunate is only interested in safe traits]



That's really cool! Surprisingly, I _did_ actually end up doing something like `BlackHole` at one point in a project. I was trying to implement a connection type so that it got automatically returned to a connection pool when dropped, but the combination of the trickiness of trying to do async things inside of a `Drop` implementation and some external requirements that were assuming a language without RAII or ownership semantics, I couldn't just pass the connection's ownership back to the pool. I ended up making a replica of the internals of the connection with I/O implementations that basically did the same thing as `BlackHole` and then swapping that out for the real connection internals and then passing a newly-constructed connection back to the pool and then letting the original connection (now with black hole internals) get dropped instead. In this case, the black hole implementations were never actually invoked for anything and were just there to satisfy the type system, but it turns out that there are bizarre cases where that might actually be useful!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: