This function wants to log its parameter out prior to doing work with it. Logger function for any type that implements Debug. We don't know the concrete type of our value at compile time, so we need to There is no general way of knowing the type of something, your values are just bytes in memory without any metadata. In Rust, types are mostly a compile-time concept, they don’t really exist when your program is running. We want to give special treatment to certain types: in thisĬase printing out the length of String values prior to their value. In dynamic languages, downcasting is trivial thanks to runtime reflection, more specifically, runtime metadata about types. We know the value we're working on implements Debug, but we don't know itsĬoncrete type. ExamplesĬonsider a situation where we want to log out a value passed to a function. Note that &Any is limited to testing whether a value is of a specifiedĬoncrete type, and cannot be used to test whether a type implements a trait. See the Box documentation for the full details. LKML Archive on help / color / mirror / Atom feed From: Miguel Ojeda <> To: Linus Torvalds <>, Greg Kroah-Hartman <> Cc:, , Jarkko Sakkinen <>, Miguel Ojeda <>, Alex Gaynor <>, Wedson Almeida.Box adds the downcast method, which attempts toĬonvert to a Box. So Cain was very angry, and his face was downcast. Is also the downcast_mut method, for getting a mutable reference to the yourselves treasures on earth, where moth and rust destroy and where thieves break in and steal. As &Any (a borrowed trait object), it has the is andĭowncast_ref methods, to test if the contained value is of a given type,Īnd to get a reference to the inner value as a type. Of any 'static type through runtime reflection.Īny itself can be used to get a TypeId, and has more features when usedĪs a trait object. This module implements the Any trait, which enables dynamic typing
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |