3 ms·
To be dynamic, "Any" should be able to represent literally ANY type. As you can find, Any is a reflection-wise trait to work with static types. It's not somethi
by EugeneOZ 8y ago
To be dynamic, "Any" should be able to represent literally ANY type. As you can find, Any is a reflection-wise trait to work with static types. It's not something what you can use when you don't know type and language will dynamically convert it. You can't write
fn example(foo: Any) -> u32 {
foo+55
}
as you CAN do in dynamic languages.
Do you understand me now? Or we will keep talking about unsafe extra special types?
- rhencke 8y agoPlease remember there's a genuine human on the other end, trying to have a respectful conversation with you.
- EugeneOZ 8y agoOr there is a person who is trying to prove his offtopic point by some pedantic interruptions, which are far from the main idea of discussion.
- foldr 8y agoYou can do that if you change it to &Any and then downcast. See the docs for examples. If the issue is that you have to downcast, then your initial claim that Rust lacks void pointers was irrelevant even if true, since you also have to downcast a void pointer in C before you can perform operations on the type that it's actually pointing to.
- EugeneOZ 8y ago> If the issue is that you have to downcast It's the difference between dynamic language and language with synthetic type for reflections.
- xfer 8y agoYou can't downcast it to anything you want, it returns an Option, void pointers in C are not certainly the same, it's unsafe.
- foldr 8y agoI know. That's why I said it's "a safe analogue of casting a void pointer to another type".