wiredport.blogg.se

Rust downcast
Rust downcast








ensuring that the type is correct) and reconstructed the Rc> pointer, it should be perfectly reasonable to get a pointer of that type, similar to how Any works.Įdit: It seems like the pointer metadata API ( tracking issue) will be the way to do this properly in unsafe code.

rust downcast

#RUST DOWNCAST CODE#

You'd probably need to use some unsafe code and make some assumptions about memory layout etc., but if you did the proper checks (e.g. The compiler is able to cast a Rc> pointer into a Rc>, so these pointers are obviously compatible: trait Trait )) A typical implementation would first down-cast this argument (throwing an. downcast downcastmut downcastrc downcastref istype. I don't think you're right about it not being possible. Many programming language type systems support subtyping. API documentation for the Rust Downcast trait in crate downcast. We'll do our best to keep these links up to date, but if we fall behind please don't hesitate to shoot us a modmail. This is not an official Rust forum, and cannot fulfill feature requests. Err on the side of giving others the benefit of the doubt.Īvoid re-treading topics that have been long-settled or utterly exhausted. Please create a read-only mirror and link that instead.Ī programming language is rarely worth getting worked up over.īe charitable in intent. If criticizing a project on GitHub, you may not link directly to the project's issue tracker. Post titles should include useful context.įor Rust questions, use the stickied Q&A thread.Īrts-and-crafts posts are permitted on weekends.Ĭriticism is encouraged, though it must be constructive, useful and actionable.

rust downcast

For content that does not, use a text post to explain its relevance. Posts must reference Rust or relate to things using Rust. We observe the Rust Project Code of Conduct. Strive to treat others with respect, patience, kindness, and empathy.

Please read The Rust Community Code of Conduct The Rust Programming LanguageĪ place for all things related to the Rust programming language-an open-source systems language that emphasizes performance, reliability, and productivity. RefCell implements Any, so one approach would be to store that inside Rc and then use Rc::downcast:: to recover the cell.






Rust downcast