Hacker News new | ask | show | jobs
by Thaxll 1572 days ago
Can't you cast to any in Rust as well?
3 comments

To expand on the others, unlike in TS/JS, Python etc you can cast to the `Any`-trait but cannot use it as if it is any value, you need to convert it to the type you want and then handle the errors. A function that accepts `&str` will never accept a `Any` value, unlike in TS where you can override the type checker using `as`. Worth noting that TypeScript's type system is unsound [0] too.

[0]: https://www.typescriptlang.org/docs/handbook/type-compatibil...

No. Rust does not have the equivalent of Object or void *.
There's the Any trait [0]. Not sure if this is exactly like void* in C, but this doesn't look particularly ergonomic to use.

[0] https://doc.rust-lang.org/std/any/index.html