logoalt Hacker News

tux3yesterday at 8:49 PM2 repliesview on HN

The Default trait provides a function that actually constructs the type in question. But here the ! type can never be constructed, so the only way to implement Default would be to have it panic, loop infinitely, or otherwise fail at runtime.

So this would risk turning a compile-time error into a runtime error.


Replies

dlubarovyesterday at 8:52 PM

Moreover, Rust traits' associated constants/types get in the way of having a proper bottom type. What would <! as Iterator>::Item be? (In Scala I think it just doesn't compile?)

show 2 replies
xg15yesterday at 8:53 PM

Ah, that makes sense. Rust noob here, so I wasn't aware traits can act on types directly without any instance of the type. Thanks for the info!

show 1 reply