Skip to content

Comment on Rust Any part 3: we have upcastsparent

Comments

people who don't know Rust and are coming from traditional OO languages.

Should those people be learning Any in the first place initially as an introduction to the language? How similar to `unsafe` is `Any` in terms of "try to avoid it"?

If you're new to Rust, you have effectively no reason to take time out to learn about the std::any::Any type. I wouldn't say it's something to "avoid"; this is unlike unsafe, where I would advise a new programmer to actively avoid it (unless they have a C background, maybe). It's just something you don't really need, and dyn traits in Rust are still relatively verbose and restrictive enough that it naturally steers you toward more idiomatic, non-dynamic code (which isn't to say that dyn traits are useless, they have their place, but it's a niche IMO).

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.