![]() For statically casting to a supertype, use upcast instead. The cast method can only be used for downcasts. In Rust, not all traits can be used as trait objects they need to satisfy certain conditions. fn cast (&self) -> Option < & T> whereT: GodotObject + SubClass , Performs a dynamic reference downcast to target type.I had a function that returned a trait object and I needed a trait object for one of its supertraits. A downcast is a trait object that is then converted to a previous concrete type, and Rust provides the Any trait to do this. This crate offers two things, a trait DynCast. If you want to downcast to concrete types instead of other trait objects then this crate can't help you, instead use std::any or a crate like downcast-rs. I recently hit a limitation of Rust when working with trait objects. This crate offers functionality for casting between trait objects using only safe Rust and no platform specific code. Copy item path src Trait Implementations Auto Trait Implementations Blanket Implementations. As we evolve a sol'n to the // coherence challenge (e.g., specialization, neg impls, etc) we can // reconsider what crate these items belong in.Traits, dynamic dispatch and upcasting Traits, dynamic dispatch and upcasting Struct trustdnsproto::error::notopenssl::SslErrorStack. Therefore, for the time being, we have // moved the `Error` trait into libstd. There, in order to both be able to operate. ![]() One thing that was brought up as a response is that its hard to implement Debug for the extension map as Any does not implement Debug. However, coherence objected to this // arrangement, because to create the blanket impls for `Box` required // knowing that `&str: !Error`, and we have no means to deal with that // sort of conflict just now. FromPyObject is also implemented for your own Rust types wrapped as Python objects (see the chapter about classes). written on Friday, JanuYesterday I wrote about how to use the Any type in Rust to implement extension maps. #! // A note about crates and the facade: // // Originally, the `Error` trait was defined in libcore, and the impls // were scattered about.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |