Printing the Extensions
with the debug formatter doesn't really yield anything:
println!("{:?}", parts.extensions);
Extensions
I know it has values since parts.extensions.len()
yields 6.
I know how to get a specific extension, but I want a way of debug printing all the values. The Extensions
is a map with types as keys, and I want to see all the keys and values inside.
I didn't find anything inside the docs.
You cannot.
Extensions
stores its data in (essentially) a HashMap<TypeId, Box<dyn Any>>
. There is no requirement that the values stored within implement Debug
, Display
, or any other representable trait. And you can't get the concrete type from a Box<dyn Any>
unless you already know (statically) what type it could be. Equally, you can't get any generic information from the TypeId
even if the Extensions
exposed it.
So unfortunately, your only insight would be from querying what types are relevant to you and print those using a series of if let Some(ext) = parts.extensions.get::<MyExt>() { ... }
or similar.