In Mojo we can define @implicit
casting constructor for the struct that allows for implicit type casting from the foreign type to the type implementing the constructor.
Is the reverse operation not possible? I find that actually this is much more common need I have, especially when interfacing with external packages that define their own types.
The @implicit
is not the classical casting approach. It just tells the compiler to call __init__
automatically without the developer explicitly calling initializer. So here it is really an instantiation of the struct and not actual casting in the classical sense.
Yeah, and I am actually fine with that. And especially as this is what is happening, I find it surprising that, as far as I know, the reverse is not possible, although I may very well be ignorant of potential problems with that. I do not have experience in programming language design at all.